a=['aaa@','bb','ccc@']
b=['aaa','bb@','ccc@']
index = 0
print "ordered comparison:"
for i,j in zip(a,b):
if i == j:
print str(index) + ": Equal"
elif i.replace("@","") == j.replace("@",""):
print str(index) + ": Not completely Matched"
else:
print str(index) + ": Different"
index+=1
print "\nunordered comparison:"
for x in a:
for y in b:
if x == y:
print x,y + " are Equal"
elif x.replace("@","") == y.replace("@",""):
print x,y + " Not completely Matched"
else:
print x,y + " Different"
列表示例:
输出:
Sets很容易逐个元素进行比较:
然后使用空集或非空集的truthiness来获取所需内容:
相关问题 更多 >
编程相关推荐