Better dict of dicts

DillonCo dillonco at comcast.net
Thu Apr 19 23:43:47 EDT 2007


On Thursday 19 April 2007, Paddy wrote:
> Martins earlier local_intern function would work for tuples as well as
> strings.

It certainly would.  I had written that class, though, primarily to offer a 
performance improvement in the __eq__ and perhaps __hash__ methods.  However, 
I ended up being rather surprised by just how much overhead there was in 
calling the Python methods vs. the builtin ones.

So really mine only ends up being useful if the tuple consists of a couple 
(i.e. 2+) of objects with Python __eq__ methods.  Oh well.

As an interesting aside:
>>> class A(object):
...     def __eq__(self, o):
...             return False
...
>>> a=A()
>>> a==a
False
>>> t=(a,)
>>> t==t
True

Apparently the tuple's __eq__ assumes:  "a is b" => "a==b"
Bug?  Or am I creating evil corner cases ;)?







More information about the Python-list mailing list