Keeping track of things with dictionaries

alex23 wuwei23 at gmail.com
Tue Apr 8 22:34:13 EDT 2014


On 8/04/2014 6:31 PM, Frank Millman wrote:
> Here is an idea, inspired by Peter Otten's suggestion earlier in this
> thread.
>
> Instead of defaultdict, subclass dict and use __missing__() to supply the
> default values.
> When the dictionary is set up, delete __missing__ from the subclass!
> Ugly, but it seems to work.

Ugly indeed. Replicating the behaviour of defaultdict and then deleting 
a method from the class seems a very heavyhanded 'solution', especially 
when you can just override a public attribute on defaultdict, as 
mentioned by Peter.





More information about the Python-list mailing list