Zip with list output instead of tuple
If you are zipping more than 2 lists (or even only 2, for that matter), a readable way would be:
[list(a) for a in zip([1,2,3], [4,5,6], [7,8,9])]
This uses list comprehensions and converts each element in the list (tuples) into lists.
You almost had the answer yourself. Don't use map
instead of zip
. Use map
AND zip
.
You can use map along with zip for an elegant, functional approach:
list(map(list, zip(a, b)))
zip
returns a list of tuples. map(list, [...])
calls list
on each tuple in the list. list(map([...])
turns the map object into a readable list.