list - Multi dimensional python dictionary -
this question has answer here:
i want create multi dimensional dictionary in python can access them using following notation:
test['system']['home']['get'] test['system']['home']['post']
what easiest way set these values, in other languages can this:
test['system']['home']['get'] = true test['system']['home']['post'] = false
you can create recursive collections.defaultdict
based structure, this
>>> collections import defaultdict >>> nesteddict = lambda: defaultdict(nesteddict) >>> >>> test = nesteddict() >>> test['system']['home']['get'] = true >>> test['system']['home']['post'] = false >>> >>> test['system']['home']['get'] true >>> test['system']['home']['post'] false
whenever access key in test
, not there in it, invoke function passed nesteddict
's argument create value key.
Comments
Post a Comment