defaultdict's bug or feature?

Rhodri James rhodri at wildebst.demon.co.uk
Thu May 21 19:46:32 EDT 2009


On Thu, 21 May 2009 13:07:50 +0100, Red Forks <redforks at gmail.com> wrote:

> from collections import defaultdict
>
> d = defaultdict(set)
> assert isinstance(d['a'], set)
> assert isinstance(d.get('b'), set)
>
> d['a'] is ok, and a new set object is insert to d, but d.get('b') won't.
>
> It's a bug, or just a feature?

Feature.  You're blaming 'get' for doing exactly what it said it would,
both in returning None and not gratuitously altering the dictionary.

-- 
Rhodri James *-* Wildebeeste Herder to the Masses



More information about the Python-list mailing list