Iterating through two lists

holger krekel pyth at devel.trillke.net
Fri May 24 06:03:58 EDT 2002


jb wrote:
> I have two lists, x and y with the property len(x) = len(y).
> 
> I should like to achive this (x is a list of class instances)
> 
>   for (a,b) in (x,y): a.f(b)

no doubt, you get hundreds of suggestions. pythoneers *love*
these kind of tasks :-)

    for (a,b) in zip(x,y): a.f(b)

would be the most straigtforward, i guess.

    holger





More information about the Python-list mailing list