Python beginner here. Reading article about list references, shallow and deep copies, tried out the following:
a = ['a', 'b', 'c']
b = list(a)
a[0] = 'A'
Expected output:
>>>a
['A', 'b', 'c']
>>>b
['A', 'b', 'c']
Actual output:
>>>a
['A', 'b', 'c']
>>>b
['a', 'b', 'c']
However, it is working in the following case:
xs = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
>>> ys = list(xs) # Make a shallow copy
xs[1][0] = 'X'
>>> xs
[[1, 2, 3], ['X', 5, 6], [7, 8, 9]]
>>> ys
[[1, 2, 3], ['X', 5, 6], [7, 8, 9]]
Can someone explain if I am missing something here? Thank you
Python 3.7.4
article link: https://realpython.com/copying-python-objects/