How do I concatenate two lists in Python?

前端 未结 25 1933
时光取名叫无心
时光取名叫无心 2020-11-21 06:18

How do I concatenate two lists in Python?

Example:

listone = [1, 2, 3]
listtwo = [4, 5, 6]

Expected outcome:

>&g         


        
25条回答
  •  余生分开走
    2020-11-21 06:50

    A really concise way to combine a list of lists is

    list_of_lists = [[1,2,3], [4,5,6], [7,8,9]]
    reduce(list.__add__, list_of_lists)
    

    which gives us

    [1, 2, 3, 4, 5, 6, 7, 8, 9]
    

提交回复
热议问题