Iterating throught 2 lists at the same time

Lee Harr missive at frontiernet.net
Thu Aug 23 23:37:25 CEST 2001


On Thu, 23 Aug 2001 17:16:17 -0400, Rajarshi Guha <rajarshi at seed.chem.psu.edu>:
> Hi,
>   I have the following construct:
> 
>>>> a = ['a','b','c']
>>>> b = ['x','y','z']
>>>> for i,j in a,b:
> ...     print i,j
> ... 
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> ValueError: unpack list of wrong size
> 
> 


how about:

for c in zip(a,b):
   print c




More information about the Python-list mailing list