id( ) function question

Luis Alberto Zarrabeitia Gomez kyrie at
Thu Oct 15 04:31:00 CEST 2009

> It's believable if id({}) does the following:
> 1. Construct an empty dict
> 2. Take the id of the dict
> 3. Reduce the reference-count on the now-unneeded dict.
> It's not too hard for the second empty dict to get allocated in the same 
> memory that the first one (now dereferenced and deallocated) used, so 
> CPython gives it the same id value.

Wow, I never thought about it, but at least in my system, it seems to work like

In [6]: id({1:2}) == id({3:4})
Out[6]: True

(only as a curiosity, though... One shouldn't rely on that)

Luis Zarrabeitia
Facultad de Matemática y Computación, UH

Participe en Universidad 2010, del 8 al 12 de febrero de 2010
La Habana, Cuba

More information about the Python-list mailing list