Take the content of a list and append it to another list

后端 未结 7 1756
死守一世寂寞
死守一世寂寞 2020-12-07 08:55

I am trying to understand if it makes sense to take the content of a list and append it to another list.

I have the first list created through a loop function, that

7条回答
  •  醉话见心
    2020-12-07 09:15

    Using the map() and reduce() built-in functions

    def file_to_list(file):
         #stuff to parse file to a list
         return list
    
    files = [...list of files...]
    
    L = map(file_to_list, files)
    
    flat_L = reduce(lambda x,y:x+y, L)
    

    Minimal "for looping" and elegant coding pattern :)

提交回复
热议问题