Find elements NOT in the intersection of two lists

前端 未结 2 986
名媛妹妹
名媛妹妹 2020-12-30 02:23

So I know how to find the intersection of two lists by doing:

>>> a = [1,2,3,4,5]
>>> b = [1,3,5,6]
>>> list(set(a) & set(b))
         


        
相关标签:
2条回答
  • 2020-12-30 03:01

    Symmetric difference?

    >>> set(a).symmetric_difference(b)
    {2, 4, 6}
    
    0 讨论(0)
  • 2020-12-30 03:08

    I usually prefer a shortcut:

    set(a) ^ set(b)
    {2, 4, 6}
    
    0 讨论(0)
提交回复
热议问题