Here is the example:
>>> x = ["a","b","c"]
>>> yy = [x] * 3
>>> yy
[['a', 'b', 'c'], ['a', 'b', 'c'], ['a', 'b', 'c']]
>>> yy[0][0] = 'A'
>>> yy
[['A', 'b', 'c'], ['A', 'b', 'c'], ['A', 'b', 'c']]
>>>
When I do yy[0][0] = 'A'
, it replaced to all the first element of the sub-list. What I got from here is when I do [x] * 3
, it creates some reference to list x
but not sure how really it works. Could some one please explain?