当前要分配我的变量,我有这个:rows = [[convert[random.randint(0,7)] for _ in range(5)] for _ in range(5)]
printedrows = [("[X]","[X]","[X]","[X]","[X]","
这将创建5行随机值:
^{pr2}$
我想把“X”重新分配给数字,这样它的读数如下:('[X]', '[2]', '[X]', '[X]', '[X]', '
('[1]', '[X]', '[3]', '[0]', '[1]', '
('[X]', '[X]', '[1]', '[X]', '[X]', '
('[1]', '[X]', '[X]', '[X]', '[2]', '
('[X]', '[3]', '[X]', '[2]', '[X]', '
但是,当我使用这个时:(仅示例-位置由用户决定)convert = {0:0,1:1,2:2,3:3,4:0,5:1,6:2,7:1}
printedrows[y][x] = rows[y][x]
TypeError: 'tuple' object does not support item assignment
我能做些什么来解决这个问题,这样我就可以在没有错误的情况下更改值了吗?谢谢。在