我有一个这样的列表:
all = [[a,b,c,d],[r,d,g,s],[e,r,a,b],[p,o,i,u]....(more similar items)]
我想得到其中有多少项目是相同的,所以我需要比较all[0]
,all[1],all[2]...all[(len(all)-1)]
然后用all[1]
比较all[2],all[3]...all[(len(all)-1)]
,然后all[2]
比较all[3],all[4],...all[(len(all)-1)]
我试过这样的事情:
for i in range(len(all)):
print len(all[i] & all[i+1]) ##how many identical items shared by all[0] and all[1]
print len(all[i+1] & all[i+2])
但不知道如何继续,我想要得到的结果是:
item1 has 3 same values with item2,
has 4 same values with item3,
has 1 same values with item4....
item2 has 3 same values with item1,
has 2 same values with item3,
etc