Find non-common elements in lists

后端 未结 6 2195
离开以前
离开以前 2020-11-30 06:34

I\'m trying to write a piece of code that can automatically factor an expression. For example, if I have two lists [1,2,3,4] and [2,3,5], the code should be able to find th

6条回答
  •  既然无缘
    2020-11-30 07:05

    You can use the .__xor__ attribute method.

    set([1,2,3,4]).__xor__(set([2,3,5]))
    

    or

    a = set([1,2,3,4])
    b = set([2,3,5])
    a.__xor__(b)
    

提交回复
热议问题