Issue 16756: buggy assignment to items of a list created by a * operator (original) (raw)
The following code:
li = [[1,0]]*5 a = [[1,10], [2,20], [3,30]] for line in a: li[line[0]][0] = 2 print(li)
prints [[2,0],[2,0],[2,0],[2,0],[2,0]], but should print [[1,0],[2,0],[2,0],[2,0],[1,0]].
The output is correct if you, instead of using li = [[1,0]]*5, initialize the array as follows:
li = [] for i in range(5): li.append([1,0])