我需要能够增加其中一个元素的值,但我会不断得到任何人帮助的错误。
Table = {56:[12],54:[9],58:[9],4:[8],16:[8],20:[8],
49:[8],1:[7],2:[7],11:[7],14:[7],25:[7],
30:[7],35:[7],36:[7],41:[7],50:[7],52:[7],
55:[7],59:[7],18:[6],21:[6],27:[6],42:[6],
45:[6],6:[5],7:[5],13:[5],17:[5],29:[5],32:[5],
34:[5],37:[5],44:[5],47:[5],5:[4],8:[4],10:[4],
15:[4],24:[4],43:[4],46:[4],51:[4],3:[3],12:[3],
19:[3],22:[3],23:[3],26:[3],38:[3],39:[3],40:[3],
53:[3],9:[2],28:[2],31:[2],33:[2],57:[2],48:[1]}
print(str(Table[1]))
x = Table[1]
Table[1]= [x+1]
print(str(Table[1]))
[7]
Traceback (most recent call last):
File "N:\CS Predictive algorithm\CS Predictive algorithm\CodeRelated\test.py", line 14, in <module>
Table[1]= [x+1]
TypeError: can only concatenate list (not "int") to list
答案 0 :(得分:0)
问题是Table[1]
是一个列表,所以你不能给它添加一个整数。
这应该有效:
Table[1][0] = Table[1][0] + 1