Why For Loop Skips the Last element?

Mark Lawrence breamoreboy at yahoo.co.uk
Thu Jan 1 12:01:25 CET 2015


On 01/01/2015 09:10, Jacob Kruger wrote:
> Not sure after quick skim/scan, but, I would generally use either for I
> in range(len(inlist)): or just for it in inlist, instead of using while,
> etc.
> Stay well
>

As a rule of thumb if you're writing range(len(inlist)) you're doing it 
wrong.  For an example of how to do things correctly see the pairwise 
recipe here 
https://docs.python.org/3/library/itertools.html#itertools-recipes. 
This is available in more-itertools here 
https://pythonhosted.org/more-itertools/api.html

As an aside would you please not top post on this list, thanks.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence




More information about the Python-list mailing list