WebLinuxStudy

导航

 

a = [1, 2, 3, 4, 5]
b = [3, 4, 5, 6, 7]

# a与b合并在一起组成的集合
c = list(set(a).union(set(b)))
print(c)
# c = [1, 2, 3, 4, 5, 6, 7]

# a中存在,而且b中也存在
d = list(set(a).intersection(set(b)))
print(d)
# d = [3, 4, 5]

# a中存在,而且b中不存在
e = list(set(a).difference(set(b)))
print(e)
# e = [1, 2]

# b中存在,而且a中不存在
f = list(set(b).difference(set(a)))
print(f)
# f = [6, 7]


posted on 2022-10-27 16:21  WebLinuxStudy  阅读(159)  评论(0)    收藏  举报