How do I concatenate two lists in Python?

前端 未结 25 1981
时光取名叫无心
时光取名叫无心 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:52

    If you want to merge the two lists in sorted form, you can use the merge function from the heapq library.

    from heapq import merge
    
    a = [1, 2, 4]
    b = [2, 4, 6, 7]
    
    print list(merge(a, b))
    

提交回复
热议问题