如何计算 交集、并集、差集?
直接上代码:
listA = [1, 2, 3, 4, 5, 6]
listB = [4, 5, 6, 7]
# Intersection
inte = list(set(listA).intersection(set(listB)))
print "Intersection:", inte
# union
uni = list(set(listA).union(set(listB)))
print "Union:", uni
# Differences
diff = list(set(listA).difference(set(listB)))
print "Differences:", diff