Iterating through multiple sequences
Harvey Thomas
hst at empolis.co.uk
Thu Oct 31 05:58:08 EST 2002
Mark Charsley wrote:
>
> In several cases recently I've wanted to iterate through two
> sequences at
> the same time. The way I've been doing it so far is
>
> assert(len(myList1) == len(myList2))
> for i in range(len(myList1)):
> doSomethingWith(myList1[i],myList2[i])
>
> which is a little ugly. Is there some clever idiom I'm
> missing that would
> simplify things? Something like
>
> for elem1,elem2 in myList1,myList2:
> doSomethingWith(elem1,elem2)
>
> which, while valid python, doesn't do what I hoped for
>
> TIA
>
> Mark
>
assert(len(myList1) == len(myList2))
map(doSomethingWith, myList1, myList2)
Harvey
_____________________________________________________________________
This message has been checked for all known viruses by the MessageLabs Virus Scanning Service.
More information about the Python-list
mailing list