any such thing as list interleaving?

Tom Plunket tomas at fancy.org
Sat Jul 12 17:00:49 EDT 2003


I find myself often doing the following sort of thing (sorry for
lack of whitespace, I don't want the line to break):

for entry, index in map(lambda e,i:(e,i),aList,range(len(aList)):
   # ...

This definitely seems like a roundabout way to loop through
parallel lists together.  Is this map routine truly the easiest/
best/most straight-forward way to do a for loop through parallel
lists, if I feel that the Python anti-idom of:

for index in range(len(myList)):
   entry = aList(index)
   anotherEntry = anotherList(index)
   # ...

???

This also brings up a similar problem for me when iterating over
dictionaries:

for key in myDict:
   value = myDict[key]
   # ...

This seems a pretty sloppy way to go about it, imo.  There must
be something more in the Python spirit!  :)

Thanks.

-tom!




More information about the Python-list mailing list