flatten list of lists of lists to a list of lists

前端 未结 4 1421
耶瑟儿~
耶瑟儿~ 2020-12-07 03:27

I\'ve already searched SO for how to flatten a list of lists (i.e. here:Making a flat list out of list of lists in Python) but none of the solutions I find addresses flatten

4条回答
  •  粉色の甜心
    2020-12-07 03:53

    For this particular case,

    In [1]: [sum(x,[]) for x in my_list]
    Out[1]: [[1, 2, 3, 4, 5], [9, 8, 9, 10, 3, 4, 6], [1]]
    

    is the shortest and the fastest method:

    In [7]: %timeit [sum(x,[]) for x in my_list]
    100000 loops, best of 3: 5.93 µs per loop
    

提交回复
热议问题