如何统计python list中元素的个数及其位置

2025-03-29 23:26:58
推荐回答(1个)
回答1:

l=[1,1,1,2,2,2,3,3,3,4]
total=len(l) #l总共的元素个数
e=1
howmany=l.count(e) #e在l中的个数
where=[i for i in range(len(l)) if l[i]==e] #e在l中的下标