2 ms·
What I meant was what if the outer list had a ref count of two, like if x and y in the following code sample were automatically elided into a single list with a
by quietbritishjim 8y ago
What I meant was what if the outer list had a ref count of two, like if x and y in the following code sample were automatically elided into a single list with a distinct ref count of 2:
x = [[1, 2], 3]
y = [[1, 2], 3]
x[0][0] = 9 # the nested list needs to notify its owner(s)
Now I think about it, I realise that this could be a harder situation to get into than I had thought at first. As the snippet above shows, it can happen if you have a a compiler/interpreter that interns entire nested lists at once. But assuming that COW lists are only formed by trying to copy existing lists, I'm not sure it's possible to end up in this situation. In real Python, if y=list(x) then changing x[0][0] should change y[0][0], as you said.