0

The example applied the function zip to two alist is this:

x = [1, 2, 3]
y = [4, 5, 6]
zipped = zip(x, y)
#show
list(zipped)
[(1, 4), (2, 5), (3, 6)]

But now if I've some like :

array = [   [1,2,3], [3,4,5] , [6,7,8] ... ]

How to applied the function zip to show some like:

[(1,3,6,...),(2,4,7,...),(3,5,8,...),... (....) ]
karthikr
  • 97,368
  • 26
  • 197
  • 188
Cristian
  • 1,480
  • 5
  • 32
  • 65

1 Answers1

5

You need argument unpacking via the "splat" or "star" operator:

zip(*array)

example:

>>> array = [   [1,2,3], [3,4,5] , [6,7,8]  ]
>>> print ( list(zip(*array)) )
[(1, 3, 6), (2, 4, 7), (3, 5, 8)]
mgilson
  • 300,191
  • 65
  • 633
  • 696