Re: dict: retrieve the original key by key

2011-05-15 Thread Ian Kelly
On Sun, May 15, 2011 at 4:18 AM, Steven D'Aprano wrote: > On Sun, 15 May 2011 11:11:41 +0200, Christoph Groth wrote: > >> 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. > > Based on the idea of interning,

Re: dict: retrieve the original key by key

2011-05-15 Thread Chris Rebert
On Sun, May 15, 2011 at 1:53 PM, Terry Reedy wrote: > On 5/15/2011 6:46 AM, Christoph Groth wrote: >> But hey, they keys of my dictionary are actually strings, so I can use >> the built-in intern.  Somehow, I have never stumbled accross this >> built-in function so far. > > It was, however, remov

Re: dict: retrieve the original key by key

2011-05-15 Thread Terry Reedy
On 5/15/2011 6:46 AM, Christoph Groth wrote: Steven D'Aprano writes: On Sun, 15 May 2011 11:11:41 +0200, Christoph Groth wrote: 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. Python hashed collection

Re: dict: retrieve the original key by key

2011-05-15 Thread Christoph Groth
Steven D'Aprano writes: > On Sun, 15 May 2011 11:11:41 +0200, Christoph Groth wrote: > >> 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. > > Based on the idea of interning, which is used for Python strin

Re: dict: retrieve the original key by key

2011-05-15 Thread Steven D'Aprano
On Sun, 15 May 2011 11:11:41 +0200, Christoph Groth wrote: > 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. Based on the idea of interning, which is used for Python strings: cache = {} def my_intern(obj)

Re: dict: retrieve the original key by key

2011-05-15 Thread Christoph Groth
Chris Rebert writes: > On Sun, May 15, 2011 at 1:28 AM, Christoph Groth 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

Re: dict: retrieve the original key by key

2011-05-15 Thread Chris Rebert
On Sun, May 15, 2011 at 1:28 AM, Christoph Groth wrote: > Dear python experts, > > 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 memo

dict: retrieve the original key by key

2011-05-15 Thread Christoph Groth
Dear python experts, 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 sever