【发布时间】:2019-12-16 19:33:38
【问题描述】:
我正在尝试使用 pygame 创建 The Game of Life。我已经创建了网格,我能够填充单元格,然后将它们作为布尔值添加到 2D 列表中(如果填充为真)一切都会相应地进行,但我想提取填充的单元格并将它们放入字典并使用它的坐标作为键,布尔值作为值
populated_dict = {}
populated_dict[[y_index, x_index]] = arrCells[y_index][x_index]
我想实现这样的目标,但我得到: 类型错误:不可散列类型:“列表”。 有没有其他方法可以做到这一点?
【问题讨论】:
-
populated_dict[(y_index, x_index)] = arrCells[y_index][x_index]?使它成为一个元组
标签: python dictionary