[Tutor] Iterate Suggestion

Dave Angel d at davea.name
Sat Apr 14 21:22:43 CEST 2012


On 04/14/2012 01:55 PM, Tom Tucker wrote:
> All,
> Thanks for the help.

Please try to post your messages AFTER the part you're quoting.

Another very useful feature is enumerate().   Instead of doing

for item in mylist:
     count += 1
     if count...

do something like:

for index, item in enumerate(mylist):
     if index%3 == 0:   #the modulo operator is also very useful
           print
     print item,



-- 

DaveA



More information about the Tutor mailing list