defaultdict's bug or feature?
redforks at gmail.com
Fri May 22 02:44:37 CEST 2009
You mean 'get' method should not alter the dict, does 'dict[key]' should not
alter the dict either?
d = defaultdict(set)
assert len(d) == 0
assert len(d) == 1
auto insert value to dict, when value is not in dict, is what defaultdict
try to do.
On Fri, May 22, 2009 at 7:46 AM, Rhodri James
<rhodri at wildebst.demon.co.uk>wrote:
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list