如何编写代码统计输出个类型的数量

img


from collections import Counter
c = Counter(ls)
print (dict(c))


dictInfo = {}
for name in data:
    if name not in dictInfo:
        dictInfo[name] = 1
    else:
        dictInfo[name] += 1

for name,value in dictInfo.items():
    print(name + ": " + value,end=" ")
        

如果觉得答案对你有帮助,请点击下采纳,谢谢~