python统计列表内元素个数




代码如下:
list01 = ['a','b','c','a','c']
set01 = set(list01)

print(set01)

dict01 = {}

for item in set01:
    dict01.update({item:list01.count(item)})
print(dict01)

 结果:

'c', 'b', 'a'}
{'c': 2, 'b': 1, 'a': 2}
自己不努力,谁也给不了自己想要的生活
原文地址:https://www.cnblogs.com/zhangyux/p/5999109.html