【发布时间】:2023-04-09 15:28:02
【问题描述】:
我想计算每个名字在字典中出现的次数(如下):
这是我的字典:
{'blue': ['Jules', 'Lucie'],
'brown': ['Maxime'],
'green': ['Maxime', 'Vincent', 'Lucie']}
这是我的代码:
from collections import Counter
Counter(dico.values())
我有这个错误:TypeError: unhashable type: 'list'
这是我想要的结果:
Jules 1
Lucie 2
Maxime 2
Vincent 1
【问题讨论】:
-
你的预期输出是什么?
标签: python list dictionary collections counter