iterating over two arrays in parallel?

skip at skip at
Fri Aug 29 03:39:34 CEST 2008

>>>>> "mark" == mh  <mh at> writes:

    mark> I want to interate over two arrays in parallel, something like this:
    mark>     a=[1,2,3]
    mark>     b=[4,5,6]

    mark>     for i,j in a,b:
    mark>         print i,j

    mark> where i,j would be 1,4,    2,5,   3,6  etc.

    a = [1,2,3]
    b = [4,5,6]
    for (i,j) in zip(a,b):
      print i, j

To avoid recreating the entire list you can substitute itertools.izip for


More information about the Python-list mailing list