2、效率较高的、并且可以去除重复数据的做法: >>> a=[1,2,3,4,5,6,7,8,9,10]>>> b=[1,2,3,4,5]>>> intersection=list(set(a).intersection(set(b)))>>>intersection [1, 2, 3, 4, 5]>>> union=list(set(a).union(set(b)))>>>union [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]>>> difference =list(set(a).d...
>>> print(list(set(a).intersection(set(b))) [3] 1. 2. 3. 4. 或者 >>> [x for x in a if x in b] [3] 1. 2. 2.3 两个list的差集 >>> a = [1, 2, 3] >>> b = [3, 4, 5] >>> list(set(b).difference(set(a))) [4, 5] >>> list(set(a).difference(set(b...
u=b print('u is ',list(set(u)))# u is [1, 2, 3, 4, 5, 6, 7] print('dif is ', dif)# dif is [1, 4, 5] print('intersec is ', intersec)# intersec is [2, 3] '''方法三,调用库函数,集合操作''' a=[1,2,3,4,5] b=[2,3,6,7] intersec=list(set(a).intersecti...
2. list