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

 

posted @ 2017-03-19 10:52  随便了888  阅读(4286)  评论(0编辑  收藏  举报