Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python zip single list element

Tags:

python

I have this:

t=[(1,2,3),(4,5,6),(11,22,33),(44,55,66)]

and want to get this :

[(1,4,11,44),(2,5,22,55),(3,6,33,66)]

How to do it in a pythonic way.

like image 791
Co Koder Avatar asked Nov 21 '25 18:11

Co Koder


1 Answers

Use star(*). It can unpacking argument lists.

>>> zip(*t)
[(1, 4, 11, 44), (2, 5, 22, 55), (3, 6, 33, 66)]

For example:

>>> args = [3, 6]
>>> range(*args)            # It's equivalent to range(3, 6)
[3, 4, 5]
like image 127
Puffin GDI Avatar answered Nov 24 '25 07:11

Puffin GDI



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!