当我向列表添加列表时,结果是正确长度的列表,但所有列表都相同,我添加的最后一个列表
代码:
cycle_points = []
for i in range(games_per_cycle):
points = game.game_cycle()
print(points)
cycle_points.append(points)
print(cycle_points)
按照建议here将cycle_points = []
更改为cycle_points = [[] for n in range(games_per_cycle)]
时,无效。
示例输出:
[26.0, 26.0, 2.0, 22.0, 12.0]
[7.0, 23.0, 19.0, 1.0, 2.0]
[21.0, 28.0, 2.0, 12.0, 2.0]
[17.0, 26.0, 4.0, 25.0, 4.0]
[1.0, 30.0, 22.0, 15.0, 20.0]
[0.0, 19.0, 23.0, 6.0, 24.0]
[17.0, 15.0, 24.0, 2.0, 35.0]
[27.0, 5.0, 15.0, 17.0, 4.0]
[2.0, 24.0, 6.0, 26.0, 14.0]
[27.0, 11.0, 5.0, 12.0, 26.0]
[[27.0, 11.0, 5.0, 12.0, 26.0], [27.0, 11.0, 5.0, 12.0, 26.0], [27.0, 11.0, 5.0, 12.0, 26.0], [27.0, 11.0, 5.0, 12.0, 26.0], [27.0, 11.0, 5.0, 12.0, 26.0], [27.0, 11.0, 5.0, 12.0, 26.0], [27.0, 11.0, 5.0, 12.0, 26.0], [27.0, 11.0, 5.0, 12.0, 26.0], [27.0, 11.0, 5.0, 12.0, 26.0], [27.0, 11.0, 5.0, 12.0, 26.0]]
完整代码https://github.com/aoskarih/5wonders/blob/master/main.py如果有帮助的话。