Python-list Digest, Vol 48, Issue 301

Jeff McNeil jeff at jmcneil.net
Thu Sep 20 11:30:03 EDT 2007


Zip do what you want?

Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> l1 = [1,2,3,4,5]
>>> l2 = ['a', 'b', 'c', 'd', 'e']
>>> for i,j in zip(l1, l2):
...     print i,j
...
1 a
2 b
3 c
4 d
5 e
>>>

You can also do the same thing using itertools.izip, but it will
return an iterator as opposed to building a new list.

-Jeff

On 9/20/07, Christoph Scheit <cscheit at lstm.uni-erlangen.de> wrote:
> Hello,
>
> is there a way to do something like
> for i,j in l1, l2:
>     print i,j
>
> ?
> Thanks in advance,
> Chris
>
> --
>
> ============================
> M.Sc. Christoph Scheit
> Institute of Fluid Mechanics
> FAU Erlangen-Nuremberg
> Cauerstrasse 4
> D-91058 Erlangen
> Phone: +49 9131 85 29508
> ============================
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list