Python zip single list element

后端 未结 1 1609
一生所求
一生所求 2021-01-21 03:01

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


        
相关标签:
1条回答
  • 2021-01-21 03:07

    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]
    
    0 讨论(0)
提交回复
热议问题