+2 votes
in Programming Languages by (6.7k points)

The zip() function outputs the tuple. How can I get the list instead of the tuple?

E.g.

>>> a=[1,3,5,7]

>>> b=[2,4,6,8]

>>> zip(a,b)

[(1, 2), (3, 4), (5, 6), (7, 8)]

My desired output is [[1, 2], [3, 4], [5, 6], [7, 8]]

1 Answer

0 votes
by (12.7k points)

You can use map() function to convert tuple to list. Check this example:

>>> a=[1,3,5,7]
>>> b=[2,4,6,8]
>>> zip(a,b)
[(1, 2), (3, 4), (5, 6), (7, 8)]
>>> map(list, zip(a,b))
[[1, 2], [3, 4], [5, 6], [7, 8]]

...