首页 > 代码库 > python 删除/查找重复项

python 删除/查找重复项

l = [1,2,3,2,1]

# l = [‘你‘,‘我‘,‘他‘,‘她‘,‘你‘]  
for i in l:
print("the %s has found %s" % (i, l.count(i))) #find duplicate number
# print("the %s has found %s" % (i, l.count(i)))    #find duplicate string
#the method above would repeat count duplicate data ,so we need to remove duplicate first
print ‘split line ----------------------------‘
s = set(l)
for j in s:
print("the %s has found %s" % (j, l.count(j))) #find duplicate number

技术分享

 

python 删除/查找重复项