On Wed, Oct 14, 2009 at 4:19 PM, Chris Rebert <c...@rebertia.com> wrote:

> Although I have no idea how it is that `id({}) == id({})` as a prior
> posted showed; FWIW, I can't manage to reproduce that outcome.
>

With Python 2.5.1 on MacOS X, I can; it looks like there's an optimization
in there where its 'saving' dictionaries that are created but not used, and
then using those saved dictionaries until they're really used, instead of
making new ones all the time.

At least that's how I interpret this output (comments added after-the-fact):
>>> id({}) # at this point a dictionary appears to be created  (though it
may have happened earlier)
6296752
>>> id({}) # previous dictionary wasn't used, so was saved; and now instead
of creating a new one, it'll just use what's on the waiting list
6296752
>>> id({}) == id({})
True
>>> x = {} # that same dictionary still hasn't been used, but now it is
right here-- so the waiting list is empty.
>>> y = {} # and a new one is made!
>>> id(x)
6296752
>>> id(y)
6299344
>>> id({})
6349136
>>> id({})
6349136
>>> z = {}
>>> id(z)
6349136
>>> id({})
7214832

--S
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to