On Aug 17, 4:25 am, Paul McGuire <[EMAIL PROTECTED]> wrote:
> In responding to another post on defaultdict, I posted an
> implementation of a 2-level hashtable, by creating a factory method
> that returned a defaultdict(dict). The OP of that other thread was
> trying to build a nested tree from a
Any reason why this wouldn't work?
>>> from collections import defaultdict
>>> def rdict(*args, **kw):
... return defaultdict(rdict, *args, **kw)
...
>>> d = rdict()
>>> d[1][2][3][4][5] # ...
defaultdict(, {})
~ Daniel
--
http://mail.python.org/mailman/listinfo/python-list
Paul McGuire wrote:
> On Aug 16, 11:19 pm, Carsten Haese <[EMAIL PROTECTED]> wrote:
>> On Thu, 2007-08-16 at 20:25 -0700, Paul McGuire wrote:
>>> [...]
>>> I've hacked out this recursivedefaultdict which is a
>>> defaultdict(defaultdict(defaultdict(...))), arbitrarily deep depending
>>> on the keys
On Thu, 2007-08-16 at 21:27 -0700, Paul McGuire wrote:
> Of course, very short and sweet! Any special reason you wrote:
> self.default_factory = type(self)
> instead of:
> self.default_factory = recursivedefaultdict
> ?
Besides a pathological need to be clever? ;) The former keeps
On Aug 16, 11:19 pm, Carsten Haese <[EMAIL PROTECTED]> wrote:
> On Thu, 2007-08-16 at 20:25 -0700, Paul McGuire wrote:
> > [...]
> > I've hacked out this recursivedefaultdict which is a
> > defaultdict(defaultdict(defaultdict(...))), arbitrarily deep depending
> > on the keys provided in the refere
On Thu, 2007-08-16 at 20:25 -0700, Paul McGuire wrote:
> [...]
> I've hacked out this recursivedefaultdict which is a
> defaultdict(defaultdict(defaultdict(...))), arbitrarily deep depending
> on the keys provided in the reference.
>
> Please comment.
> [...]
>
> class recursivedefaultdict(object
In responding to another post on defaultdict, I posted an
implementation of a 2-level hashtable, by creating a factory method
that returned a defaultdict(dict). The OP of that other thread was
trying to build a nested tree from a set of n-tuples, in which the
first (n-1) values in each tuple were