Zip with list output instead of tuple

前端 未结 7 2038
梦毁少年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:46

    How about this?

    >>> def list_(*args): return list(args)
    
    >>> map(list_, range(5), range(9,4,-1))
    [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]
    

    Or even better:

    >>> def zip_(*args): return map(list_, *args)
    >>> zip_(range(5), range(9,4,-1))
    [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]
    

提交回复
热议问题