Nice way of getting items from two lists

Yermat loic at yermat.net1.nerim.net
Wed Mar 10 13:06:14 EST 2004


SBrunning at trisystems.co.uk a écrit :
>>From: C GIllespie [mailto:csgcsg39 at hotmail.com]
>>
>>I have two equal size lists - list1, list2. Basically, each 
>>item in list 1
>>has a partner in list2. I was wanting to do something like
>>So if:
>>list1=['x','y','z']
>>list2=[1,2,3]
>>
>>then if I did this 'for loop'
>>for name, value in list1,list2:
>>    print name, value
>>
>>I would get
>>x,1
>>y,2
>>z,3
> 
> 
> for name, value in zip(list1, list2):
>     print name, value

or with itertools.izip
see http://www.python.org/doc/2.3.3/lib/itertools-functions.html

Yermat




More information about the Python-list mailing list