Combining two lists and removing duplicates, without removing duplicates in original list

后端 未结 11 1868
逝去的感伤
逝去的感伤 2020-11-28 04:53

I have two lists that i need to combine where the second list has any duplicates of the first list ignored. .. A bit hard to explain, so let me show an example of what the c

11条回答
  •  清歌不尽
    2020-11-28 05:14

    You can use sets:

    first_list = [1, 2, 2, 5]
    second_list = [2, 5, 7, 9]
    
    resultList= list(set(first_list) | set(second_list))
    
    print(resultList)
    # Results in : resultList = [1,2,5,7,9]
    

提交回复
热议问题