python unzip list of tuples 1

python unzip list of tuples

>>> [list(t) for t in zip(*l)]
[[1, 3, 8], [2, 4, 9]]

Here is what the above code is Doing:
1. zip(*l) takes the list l and transposes it.
2. list(t) converts the tuples in the transposed list to lists.
3. [list(t) for t in zip(*l)] is a list comprehension that does the above two steps.

Similar Posts