我正在尝试设置一个游戏板,并使用列表标记行和单元格。然而,python似乎认为我在做元组,这不是故意的。
type1 = {"Contents": "", "Type": "A"} type2 = {"Contents": "", "Type": "B"} type3 = {"Contents": "", "Type": "C"} board = [ [type1, type2, type1] [type1, type3, type1] [type3, type2, type1] ] return board
我本以为会有一份字典列表,结果却得到了:
TypeError: list indices must be integers or slices, not tuple
试试这个:
board = [ [type1, type2, type1], [type1, type3, type1], [type3, type2, type1], ]
我想你只是漏掉了逗号。