将列表设置为字典值会导致TypeError:无法散列的类型:'list'

时间:2020-05-04 08:07:18

标签: python python-3.x dictionary xlsx

我正在尝试通过python脚本将.xlsx文件转换为json文件。

output['operators'] = {}

for y in range(marks[0][0]+1, marks[1][0]-2):
    ops = [CTUs.get(o,o) for o in workbook.cell_value(y,2).split('/')]

    for op in ops:
        if not op in list(output['operators']):
            output['operators'][op] = {
                'name':op,
                'guns':[]
            }

        name = workbook.cell_value(y,2)
        output['operators'][op]['guns'].append(name if name != 417 else '417') #Dry this code later

在第十行('guns':[])上,出现类型错误:TypeError: unhashable type: 'list'。我不知道为什么和AFAIK,键是唯一需要哈希的部分。

0 个答案:

没有答案