Zip with list output instead of tuple

前端 未结 7 2040
梦毁少年i
梦毁少年i 2020-12-07 12:57

What is the fastest and most elegant way of doing list of lists from two lists?

I have

In [1]: a=[1,2,3,4,5,6]

In [2]: b=[7,8,9,10,11,12]

In [3]: z         


        
7条回答
  •  孤街浪徒
    2020-12-07 13:49

    List comprehension would be very simple solution I guess.

    a=[1,2,3,4,5,6]
    
    b=[7,8,9,10,11,12]
    
    x = [[i, j] for i, j in zip(a,b)]
    
    print(x)
    
    output : [[1, 7], [2, 8], [3, 9], [4, 10], [5, 11], [6, 12]]
    

提交回复
热议问题