erik gartz wrote:
> 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?
each time it's *executed*, yes. [{}]*3 doesn'
erik gartz wrote:
> 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[
"erik gartz" <[EMAIL PROTECTED]> writes:
> Doesn't {} allocate new memory for the dictionary each time? It
> almost appears as if the 2nd dictionary created overwrites the first
> one.
http://effbot.org/pyfaq/how-do-i-create-a-multidimensional-list.htm>
--
\"There are only two ways
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 f