Get difference between two lists

前端 未结 27 2806
傲寒
傲寒 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:56

    Here is an simple way to distinguish two lists (whatever the contents are), you can get the result as shown below :

    >>> from sets import Set
    >>>
    >>> l1 = ['xvda', False, 'xvdbb', 12, 'xvdbc']
    >>> l2 = ['xvda', 'xvdbb', 'xvdbc', 'xvdbd', None]
    >>>
    >>> Set(l1).symmetric_difference(Set(l2))
    Set([False, 'xvdbd', None, 12])
    

    Hope this will helpful.

提交回复
热议问题