Re: Why defaultdict?

2010-07-02 Thread Steven D'Aprano
On Fri, 02 Jul 2010 04:11:49 +, Steven D'Aprano wrote: > I would like to better understand some of the design choices made in > collections.defaultdict. [...] Thanks to all who replied. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Why defaultdict?

2010-07-02 Thread Thomas Jollans
On 07/02/2010 11:26 AM, Chris Rebert wrote: > On Fri, Jul 2, 2010 at 2:20 AM, Thomas Jollans wrote: >> On 07/02/2010 06:11 AM, Steven D'Aprano wrote: >>> I would like to better understand some of the design choices made in >>> collections.defaultdict. > >>> Second, why is the factory function not

Re: Why defaultdict?

2010-07-02 Thread Chris Rebert
On Fri, Jul 2, 2010 at 2:20 AM, Thomas Jollans wrote: > On 07/02/2010 06:11 AM, Steven D'Aprano wrote: >> I would like to better understand some of the design choices made in >> collections.defaultdict. >> Second, why is the factory function not called with key? There are three >> obvious kinds o

Re: Why defaultdict?

2010-07-02 Thread Thomas Jollans
On 07/02/2010 06:11 AM, Steven D'Aprano wrote: > I would like to better understand some of the design choices made in > collections.defaultdict. > > Firstly, to initialise a defaultdict, you do this: > > from collections import defaultdict > d = defaultdict(callable, *args) > > which sets an at

Re: Why defaultdict?

2010-07-01 Thread Raymond Hettinger
On Jul 1, 9:11 pm, Steven D'Aprano wrote: > I would like to better understand some of the design choices made in > collections.defaultdict. . . . > If callable is None, defaultdicts are > *exactly* equivalent to built-in dicts, so I wonder why the API wasn't > added on to dict rather than a separ

Re: Why defaultdict?

2010-07-01 Thread Chris Rebert
On Thu, Jul 1, 2010 at 9:11 PM, Steven D'Aprano wrote: > I would like to better understand some of the design choices made in > collections.defaultdict. Perhaps python-dev should've been CC-ed... > Firstly, to initialise a defaultdict, you do this: > > from collections import defaultdict > d = d

Why defaultdict?

2010-07-01 Thread Steven D'Aprano
I would like to better understand some of the design choices made in collections.defaultdict. Firstly, to initialise a defaultdict, you do this: from collections import defaultdict d = defaultdict(callable, *args) which sets an attribute of d "default_factory" which is called on key lookups wh