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

如题所述

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中的下标

温馨提示:答案为网友推荐,仅供参考
相似回答