Re: simple question re list iteration semantics

2009-04-21 Thread Esmail
Paul Rubin wrote: Esmail writes: for i in range(0, len(li)): print li[i] Will this always be equivalent to for i in li: print i Not the same--after the exit of the first loop, 'i' is the length of the list. After the exit of the second loop, 'i' is the last element. Yes, agree

Re: simple question re list iteration semantics

2009-04-21 Thread Paul Rubin
Esmail writes: > for i in range(0, len(li)): > print li[i] > > Will this always be equivalent to > > > for i in li: > print i Not the same--after the exit of the first loop, 'i' is the length of the list. After the exit of the second loop, 'i' is the last element. > Would the 2nd o

Re: simple question re list iteration semantics

2009-04-21 Thread Esmail
Thanks everyone, as usual, very informative posts! Esmail -- http://mail.python.org/mailman/listinfo/python-list

Re: simple question re list iteration semantics

2009-04-21 Thread Dave Angel
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 al

Re: simple question re list iteration semantics

2009-04-21 Thread Steven D'Aprano
On Tue, 21 Apr 2009 21:06:46 -0400, Esmail wrote: > 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 For lists, yes, that will always be equ

Re: simple question re list iteration semantics

2009-04-21 Thread MRAB
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 al

simple question re list iteration semantics

2009-04-21 Thread Esmail
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 sam