Get difference between two lists

前端 未结 27 2829
傲寒
傲寒 2020-11-21 11:36

I have two lists in Python, like these:

temp1 = [\'One\', \'Two\', \'Three\', \'Four\']
temp2 = [\'One\', \'Two\']

I need to create a third

27条回答
  •  情话喂你
    2020-11-21 11:53

    most simple way,

    use set().difference(set())

    list_a = [1,2,3]
    list_b = [2,3]
    print set(list_a).difference(set(list_b))
    

    answer is set([1])

    can print as a list,

    print list(set(list_a).difference(set(list_b)))
    

提交回复
热议问题