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't execute [] or {} three times; it executes them both once, and then creates a new list with three references to the dictionary. see: http://effbot.org/pyfaq/how-do-i-create-a-multidimensional-list.htm </F> -- http://mail.python.org/mailman/listinfo/python-list