Python Forum
looking for for loop thread - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Forum & Off Topic (https://python-forum.io/forum-23.html)
+--- Forum: Board (https://python-forum.io/forum-26.html)
+--- Thread: looking for for loop thread (/thread-21070.html)

Pages: 1 2


looking for for loop thread - metulburr - Sep-12-2019

I was gong to write up a for/while loop tutorial because we actually dont have one on here. I was going to link to key points of things that already had a tutorial. I was going to link here for illustration of not using range(len()) and there was another thread somewhere that i cannot find (Written by i think a mod or admin) about for loops. I checked through all the tutorials and could not find it. Maybe it was on another site or maybe is was just a really good response to a questions that never was moved to tutorials.

Anyone remember this? Sorry, I literally had the specific idea of the thread in mind when i started this post, but while writing i drew a blank. Coffee

EDIT:
Too early in the morning without coffee...The thread was comparing about python's for loop looping through a sequence directly as opposed to something like c/c++ for loop increment variable i++ to get through the sequence. It was somewhere in the past month or so.


RE: looking for for loop thread - buran - Sep-12-2019

is it this one you are looking for?
https://python-forum.io/Thread-Basic-Never-use-for-i-in-range-len-sequence


RE: looking for for loop thread - metulburr - Sep-12-2019

That is one I was planning on linking through. But that is not the one I was thinking of


RE: looking for for loop thread - snippsat - Sep-12-2019

Could probably borrow some stuff from Loop better: A deeper look at iteration in Python.
If look at bottom there like to eg Loop Like A Native.
Also the basic in this video Transforming Code into Beautiful, Idiomatic Python here a Gist with slides(now with f-string could improve also the printing to be more Beautiful).


RE: looking for for loop thread - ichabod801 - Sep-12-2019

Have you done much work on this yet? Because I started a for/while loop tutorial a while back, which has a bout 4k characters in it. I could maybe be persuaded to get off my butt and finish it.


RE: looking for for loop thread - wavic - Sep-12-2019

Such a tutorial should include at least a short explanation of generators and iterators.


RE: looking for for loop thread - metulburr - Sep-12-2019

Thanks snippsat for the links. Will use them.

(Sep-12-2019, 02:31 PM)ichabod801 Wrote: Have you done much work on this yet? Because I started a for/while loop tutorial a while back, which has a bout 4k characters in it. I could maybe be persuaded to get off my butt and finish it.
I have, but i dont see why we cannot have multiple tutorials for the same subject from different people. I think its better to have different perspectives.

I can post it now and soft delete it so you guys can see it. But it is unfinished and short as i just started it this morning. So it is incomplete.

(Sep-12-2019, 02:44 PM)wavic Wrote: Such a tutorial should include at least a short explanation of generators and iterators.
My tutorials tend to skim the basics instead of going into detail of everything. They are not usually for the knowledge hungry, but to use as a reference to look through. I wonder if these could be a separate tutorial?


RE: looking for for loop thread - snippsat - Sep-12-2019

(Sep-12-2019, 03:55 PM)metulburr Wrote: I wonder if these could be a separate tutorial?
They could be,but as basic overview may not need to dig to deep in as it could clutter stuff up.
Could refers to eg Trey's Loop better if someone would have deeper look into it.


RE: looking for for loop thread - metulburr - Sep-12-2019

Im done for today. By the time i got sick of writing it out i didnt have time to implement your links. But i linked them as they were good for more info. Take a scan on it for missing or incorrect material. I didnt even get to a while loop so i just named it for loops.


RE: looking for for loop thread - snippsat - Sep-13-2019

Look okay at a quick glance Thumbs Up
In list comprehensions,could add this.
# Ordinary loop with append to new list
lst = ['spam', 'ham', 'eggs', 'ham']
ham_lst = []
for item in lst:
    if item == 'ham':
        ham_lst.append(item)
print(ham_lst)

# With list lomprehensions code over become this
ham_lst = [item for item in lst if item == 'ham']
print(ham_lst)

# Both create a new list "ham_lst".
# So problems that can occur if modify the original list in the loop sequence,will not affect when create a new list 
The last links is better to give title in link than the raw url.
Example:
Loop better: A deeper look at iteration in Python