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

Popular posts from this blog

gcc - MinGW's ld cannot perform PE operations on non PE output file -

How to connect android app to App engine -

hadoop - Running Map Reduce Job shows error - Mkdirs failed to create /var/folders/ -