+2 votes
in Programming Languages by (77.0k 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

+1 vote
by (354k points)
selected by
 
Best answer

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]]


...