On Tue, Mar 6, 2012 at 6:21 PM, Alan Gauld <[email protected]> wrote:
> But it doesn't have the same dynamic depth that the Perl version has, you
> need to know your maximum depth. The last level will always have the default
> set to None.
>
> You could create a class subclassed from defaultdict that would do it
> though...
It's a pretty easy class to write:
from collections import defaultdict
class recursivedefaultdict(defaultdict):
def __init__(self):
self.default_factory = type(self)
Given that bit of code, the OP's example looks a bit like this:
a = 1
b = 2
c = 'apples'
my_hash = recursivedefaultdict()
my_hash[a][b][c] = "value"
if my_hash[a][b][c]:
print("found value")
--
Jerry
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor