考虑这个例子:
>>> result = [[]] * 8
>>> result
[[], [], [], [], [], [], [], []]
>>> result[0]
[]
>>> result[0].append("foo")
>>> result # wtf? expected result: [['foo'], [], [], [], [], [], [], []]
[['foo'], ['foo'], ['foo'], ['foo'], ['foo'], ['foo'], ['foo'], ['foo']]
我对此感到非常困惑。也许我不明白append
预期如何使用。我将如何附加到i
列表中列出的第 th 嵌套?