方法一
#统计列表重复元素的个数
mylist = [1,2,2,2,2,3,4,4,4,4]
myset = set(mylist)
for item in myset:
print("the %d has found %d" %(item,mylist.count(item)))
#方法二
List=[1,2,2,2,4,4,4,4]
a = {}
for i in List:
if List.count(i)>1:
a[i] = List.count(i)
print (a)
Python统计列表中重复元素的个数
最新推荐文章于 2024-07-06 03:10:22 发布