[Python-Dev] defaultdict proposal round three

Guido van Rossum guido at python.org
Mon Feb 20 22:32:08 CET 2006


On 2/20/06, Alex Martelli <aleaxit at gmail.com> wrote:
>
> On Feb 20, 2006, at 12:33 PM, Guido van Rossum wrote:
>     ...
> > You don't need a new feature for that use case; d[k] = d.get(k, 0) + 1
> > is perfectly fine there and hard to improve upon.
>
> I see d[k]+=1 as a substantial improvement -- conceptually more
> direct, "I've now seen one more k than I had seen before".

Yes, I now agree. This means that I'm withdrawing proposal A (new
method) and championing only B (a subclass that implements
__getitem__() calling on_missing() and on_missing() defined in that
subclass as before, calling default_factory unless it's None). I don't
think this crisis is big enough to need *two* solutions, and this
example shows B's superiority over A.

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


More information about the Python-Dev mailing list