defaultdict's bug or feature?
rhodri at wildebst.demon.co.uk
Fri May 22 06:35:39 CEST 2009
Please don't top-post, it makes the thread of argument hard to follow.
On Fri, 22 May 2009 01:44:37 +0100, Red Forks <redforks at gmail.com> wrote:
> You mean 'get' method should not alter the dict, does 'dict[key]' should
> alter the dict either?
> d = defaultdict(set)
> assert len(d) == 0
> print d
> assert len(d) == 1
> auto insert value to dict, when value is not in dict, is what defaultdict
> try to do.
Behaviour you are deliberately avoiding by calling `get`, since that
explicitly behaves the same way that it does for dicts. You're doing
two different things through two different interfaces with two different
specs. Why are you expecting them to have the same effect?
Rhodri James *-* Wildebeeste Herder to the Masses
More information about the Python-list