python3_统计重复项

 

mylist = [1,2,2,2,2,3,3,3,4,4,4,4]
myset = set(mylist)  #myset是另外一个列表,里面的内容是mylist里面的无重复 项
print(myset)
for item in myset:
    print(item,mylist.count(item))
    print("the %d has found %d" %(item,mylist.count(item)))
'''
{1, 2, 3, 4}
1 1
the 1 has found 1
2 4
the 2 has found 4
3 3
the 3 has found 3
4 4
the 4 has found 4
'''

 

posted @ 2022-02-26 17:26  小鱼小鱼hi  阅读(76)  评论(0编辑  收藏  举报