Chris Rebert <[email protected]> writes:
> On Sun, May 15, 2011 at 1:28 AM, Christoph Groth <[email protected]> wrote:
>> I use a huge python dictionary where the values are lists of that
>> dictionary's keys (yes, a graph). Each key is thus referenced
>> several times.
>>
>> As the keys are rather large objects, I would like to save memory by
>> re-using key objects wherever possible, instead of having several
>> equal objects in memory.
>>
>> There does not seem to be a way to retrieve the original key from a
>> python dictionary. Is there a technical reason for this? (Other
>> than that such functionality was not considered to be useful enough.)
>
> Define "original key".
def original_key(dictionary, key):
for k in dictionary:
if k == key:
return k
raise KeyError(key)
But this is not efficient.
I would like to avoid having _multiple_ objects which are equal (a == b)
but not the same (a is not b). This would save a lot of memory.
--
http://mail.python.org/mailman/listinfo/python-list