Re: beginner question about range with list and list

2006-11-23 Thread Fredrik Lundh
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'

Re: beginner question about range with list and list

2006-11-23 Thread Dan Lenski
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[

Re: beginner question about range with list and list

2006-11-23 Thread Ben Finney
"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

beginner question about range with list and list

2006-11-23 Thread 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 f