I've ran into an unexpected behavior when using a nested list in python, that took a while to debug. If a list is initialized like this:
a = [[None] * 2] * 2
a
[[None, None], [None, None]]
and another list initialized like this:
b = [[None, None], [None, None]]
b
[[None, None], [None, None]]
I would expect the same behavior from both these lists, but if I do:
a[0][0] = 3
a
[[3, None], [3, None]]
and if I do:
b[0][0] = 3
b
[[3, None], [None, None]]
Can someone explain the reason why this happens? thanks