我写了这个Python脚本
with open('survey_data/survey_results_public.csv', encoding='utf-8') as f:
csv_reader = csv.DictReader(f)
dev_type_info = {}
for line in csv_reader:
dev_types = line['DevType'].split(';')
for dev_type in dev_types:
dev_type_info.setdefault(dev_type_info, {
'total': 0,
'language_counter': Counter()
})
但我收到此错误
> TypeError Traceback (most recent call
> last) <ipython-input-34-0dd498f86be7> in <module>
> 14 dev_type_info.setdefault(dev_type_info, {
> 15 'total': 0,
> ---> 16 'language_counter': Counter()
> 17 })
>
> TypeError: unhashable type: 'dict'
任何人都可以在此错误上加阴影,这是什么,我该如何解决?谢谢
您收到此错误,是因为您试图使用dict
作为另一个dict
的键。更正下面的代码行: