Possible to append multiple lists at once? (Python)

后端 未结 7 544
清歌不尽
清歌不尽 2020-12-29 02:41

I have a bunch of lists I want to append to a single list that is sort of the \"main\" list in a program I\'m trying to write. Is there a way to do this in one line of code

7条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-29 03:03

    You can use sum function with start value (empty list) indicated:

    a = sum([x, y, z], [])
    

    This is especially more suitable if you want to append an arbitrary number of lists.

提交回复
热议问题