for x,y in word1, word2 ?

Raja Baz entropy88 at gmail.com
Tue Aug 12 04:08:07 EDT 2008


On Sun, 10 Aug 2008 21:40:55 -0700, Mensanator wrote:

> On Aug 10, 11:18�pm, ssecorp <circularf... at gmail.com> wrote:
>> Is there a syntax for looping through 2 iterables at the same time?
>>
>> for x in y:
>> � � for a in b:
>>
>> is not what I want.
>>
>> I want:
>> for x in y and for a in b:
> 
> Something like this?
> 
>>>> a = ['a','b','c']
>>>> b = [1,2,3]
>>>> zip(a,b)
> [('a', 1), ('b', 2), ('c', 3)]

zip and the nested loops don't do the same thing
zipping then comparing would compare items that are at the same position
the nested loops would compare each item to all the items in the other
sequence, big difference
AFAIK there's no better way to accomplish what the nested loops do with 
a simpler syntax



More information about the Python-list mailing list