E
erik gartz
Hello,
I'm new to python and I'm having difficulty understanding the following
code. Why doesn't the variable a contain [[{}, {'x': 0}, {}], [{},
{'x': 1}, {}]] instead. Doesn't {} allocate new memory for the
dictionary each time? It almost appears as if the 2nd dictionary
created overwrites the first one. Thanks for your help,
Erik
I'm new to python and I'm having difficulty understanding the following
code. Why doesn't the variable a contain [[{}, {'x': 0}, {}], [{},
{'x': 1}, {}]] instead. Doesn't {} allocate new memory for the
dictionary each time? It almost appears as if the 2nd dictionary
created overwrites the first one. Thanks for your help,
Erik
a = [[{}] * 3] * 2
a [[{}, {}, {}], [{}, {}, {}]]
for i in range(2): a[1] = {'x':i}
a [[{}, {'x': 1}, {}], [{}, {'x': 1}, {}]]