I was expecting below ways of initialization to result in same output:
a = [{}, {}]
b = [{}] * 2
a[0]["assigned"] = 1
b[0]["assigned"] = 1
print(a)
print(b)
but the output is as follows:
[{'assigned': 1}, {}]
[{'assigned': 1}, {'assigned': 1}]
Looks like in case of b, a single dictionary instance is being created and referenced in all the list elements.
Can someone help me with reason behind this implementation?
Thanks.