simple question re list iteration semantics
MRAB
google at mrabarnett.plus.com
Tue Apr 21 21:17:29 EDT 2009
Esmail wrote:
> Hello all,
>
> I have a simple question regarding semantics.
>
> Given a list 'li', I can always do this to iterate through all items in
> order:
>
> for i in range(0, len(li)):
> print li[i]
>
> Will this always be equivalent to
>
>
> for i in li:
> print i
>
> I assume it is, and the order will always be the same, or am I mistaken?
>
> Would the 2nd one be considered more Pythonic? (It looks both
> clearer and cleaner to me).
>
If you posted the first one, you would be told that the second one was
the Pythonic way.
More information about the Python-list
mailing list