Re: defaultdict of arbitrary depth

2007-08-21 Thread Paddy
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

Re: defaultdict of arbitrary depth

2007-08-21 Thread Daniel
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

Re: defaultdict of arbitrary depth

2007-08-16 Thread Steve Holden
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

Re: defaultdict of arbitrary depth

2007-08-16 Thread Carsten Haese
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

Re: defaultdict of arbitrary depth

2007-08-16 Thread Paul McGuire
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

Re: defaultdict of arbitrary depth

2007-08-16 Thread Carsten Haese
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

defaultdict of arbitrary depth

2007-08-16 Thread Paul McGuire
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