我有两个已经处理的文件列表(A,B)。列表A包含所有初始文件,列表B包含所有已成功处理的文件(因此第二个列表(B)是第一个列表的子集)
A包含231453项
B包含124769项
我想减去它们,看看哪些文件没有得到处理(C应包含106684项)
为此,我使用设置:
newlist=[]
newlist2=[]
newlist3=[]
newlist=( set(A) - ( set(A) & set(B) ) )
newlist2=(set(A)^set(B))
newlist3=(set(A) - set(B))
print len(newlist)
print len(newlist2)
print len(newlist3)
结果是:
134173
161662
134173
Why there are more items than the one expected?
你的B包含一些不在A中的项如果B是A的子集那么所有三个长度应该是相同的。事实上,你的对称差异有更高的长度,你的B包含某些项目,而不是在A
您已经指定A和B是列表。列表中有可能有重复项在转换为set时丢失
为了你的案子你可以
或者
如果x值在B中,上述代码将给出A中存在的所有x值
相关问题 更多 >
编程相关推荐