1

If I have:

>>> a=[1,2]
>>> b=[3,4]
>>> c=[5,6]

Is there a one-liner to get:

d = ([1,3,5],[2,4,6])
David542
  • 104,438
  • 178
  • 489
  • 842

1 Answers1

5
d = zip(a, b, c)

up to tuple/list differences.

Sven Marnach
  • 574,206
  • 118
  • 941
  • 841
  • Great, thanks. I was trying `zip((a,b,c))` which was giving me something else. – David542 Mar 06 '12 at 19:53
  • 2
    if you have a tuple of the lists, i.e. `(a, b, c)`, you can pass it to `zip` like so: `d = zip(*(a, b, c))`. This unpacks the tuple `(a, b, c)` to pass them as arguments to `zip`. For python 3.x, zip provides a generator, and you should use `d = tuple(zip(a, b, c))` to get `d = ([1,3,5],[2,4,6])`. – Casey Kuball Mar 06 '12 at 20:04