When I do:
cand = [ [ 0, 0 ] ] * 4
followed by:
cand[0][0] = 99
I get:
[[99, 0], [99, 0], [99, 0], [99, 0]]
does the multiplication simply copy list references? Is there a way to have distinct lists?
When I do:
cand = [ [ 0, 0 ] ] * 4
followed by:
cand[0][0] = 99
I get:
[[99, 0], [99, 0], [99, 0], [99, 0]]
does the multiplication simply copy list references? Is there a way to have distinct lists?
It creates four references to the same object. To get around that, you have to create four separate lists:
cand = [[0, 0] for _ in range(4)]