any such thing as list interleaving?
Bob Gailer
bgailer at alum.rpi.edu
Sat Jul 12 17:11:54 EDT 2003
At 02:00 PM 7/12/2003 -0700, Tom Plunket wrote:
>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)
> # ...
mergedList = zip(aList, anotherList)
>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! :)
for key, value in myDict.items():
Bob Gailer
bgailer at alum.rpi.edu
303 442 2625
-------------- next part --------------
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.500 / Virus Database: 298 - Release Date: 7/10/2003
More information about the Python-list
mailing list