id( ) function question
Luis Alberto Zarrabeitia Gomez
kyrie at uh.cu
Wed Oct 14 22:31:00 EDT 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
that:
In [6]: id({1:2}) == id({3:4})
Out[6]: True
Interesting...
(only as a curiosity, though... One shouldn't rely on that)
--
Luis Zarrabeitia
Facultad de Matemática y Computación, UH
http://profesores.matcom.uh.cu/~kyrie
--
Participe en Universidad 2010, del 8 al 12 de febrero de 2010
La Habana, Cuba
http://www.universidad2010.cu
More information about the Python-list
mailing list