[Python-Dev] Pre-PEP: Mutable keys in dictionaries

Guido van Rossum guido@python.org
Thu, 06 Feb 2003 15:02:49 -0500


> > Could you do this as a subclass of dict?  A subclass in Python would
> > be inefficient, but might still be good enough for your second use
> > case (the ObjC bridge).  If not, a subclass in Python might be
> > feasible -- it would be a little bit more work than integrating it
> > into dictobject.c, but you have a lot less convincing to do, and you
> > can even get it to work with Python 2.2.
> 
> But it doesn't solve our problem. We have no control over what
> dictionaries are used, either by our users directly or by the Python
> library they use. We _do_ have control over the keys that are causing
> troubles: our main problem is that we cannot rely on NSString instances
> to be immutable, yet we need the ability to use them as keys in
> (regular) dicts, just as if they were Python strings.

OK, go ahead and try to implement your idea, and report benchmarks
here.

--Guido van Rossum (home page: http://www.python.org/~guido/)