[Python-Dev] Proposal: defaultdict

Aahz aahz at pythoncraft.com
Mon Feb 20 16:18:08 CET 2006


On Sun, Feb 19, 2006, Josiah Carlson wrote:
>
> I agree, there is nothing perfect.  But at least in all of my use-cases,
> and the majority of the ones I've seen 'in the wild', my previous post
> provided an implementation that worked precisely like desired, and
> precisely like a regular dictionary, except when accessing a
> non-existant key via: value = dd[key] . __contains__, etc., all work
> exactly like they do with a non-defaulting dictionary. Iteration via
> popitem(), pop(key), items(), iteritems(), __iter__, etc., all work the
> way you would expect them. 

This is the telling point, IMO.  My company makes heavy use of a "default
dict" (actually, it's a "default class" because using constants as the
lookup keys is mostly what we do and the convenience of foo.bar is
compelling over foo['bar']).  Anyway, our semantics are as Josiah
outlines, and I can't see much use case for the alternatives.

Those of you arguing something different: do you have a real use case
(that you've implemented in real code)?
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"19. A language that doesn't affect the way you think about programming,
is not worth knowing."  --Alan Perlis


More information about the Python-Dev mailing list