Sequence traversal
Skip Montanaro
skip at mojam.com
Thu Sep 23 12:24:35 EDT 1999
Sven> List traversal is elegant in python! - But what if I want to step
Sven> through two sequences in parallel?
map() is your friend! Try:
l1 = list("Names ")
l2 = [4,2,1,5,3,9]
for i, j in map(None, l1, l2):
print i, j
This can be extended for any number of lists. map(None, ...) will generate
a list of n-tuples, where n is the number of lists you feed it.
Skip Montanaro | http://www.mojam.com/
skip at mojam.com | http://www.musi-cal.com/
847-971-7098 | Python: Programming the way Guido indented...
More information about the Python-list
mailing list