How to take two lists and combine them excluding any duplicates?

后端 未结 5 690
無奈伤痛
無奈伤痛 2021-02-04 07:26

I\'d like to make one list from two separate lists of unique items.

There are other similar questions but there didn\'t seem to be any that concerned doing this problem

5条回答
  •  星月不相逢
    2021-02-04 08:04

    If someone want to do it without set():

    a = [1,2,3]
    b = [2,3,4]
    newlist=[]
    for i in a:
        newlist.append(i)
    for z in b:
        if z not in newlist:
            newlist.append(z)
    newlist.sort()
    print newlist
    

提交回复
热议问题