Opposite of set.intersection in python?

前端 未结 5 556
你的背包
你的背包 2020-12-24 11:20

In Python you can use a.intersection(b) to find the items common to both sets.

Is there a way to do the disjoint opposite version of this? Ite

5条回答
  •  遥遥无期
    2020-12-24 12:11

    Try this code for (set(a) - intersection(a&b))

    a = [1,2,3,4,5,6]
    b = [2,3]
    
    for i in b:
       if i in a:
          a.remove(i)
    
    print(a)
    

    the output is [1,4,5,6] I hope, it will work

提交回复
热议问题