我还有一本字典
maketh = {'n':['1', '2', '3'], 'g': ['0', '5', '6', '9'], 'ca': ['4', '8', '1', '5', '9', '0']}
我打算改成
maketh_new = {'n':[1, 2, 3], 'g': [0, 5, 6, 9], 'ca': [4, 8, 1, 5, 9, 0]}
数字在值中的顺序非常重要.因此,顺序应该保持不变
当我try 使用任何在线可用的方法进行更改时,总是会遇到以下错误:
TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'
"如果有任何打字错误,请忽略……"
我自己写的一个 idea 可能是这样的:
maketh_new = dict()
for (key, values) in maketh.items():
for find in len(values):
maketh_new [key] = int(values[find])
我试着想,如果我能以字符串的形式访问列表中的所有值元素,那么我可能可以将其输入int.但我得到一个错误:
'list' object cannot be interpreted as an integer
所以如果有人能帮我找到解决办法,请做吧...