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
print d[1]
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
<rho...@wildebst.demon.co.uk>wrote:

> On Thu, 21 May 2009 13:07:50 +0100, Red Forks <redfo...@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
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to