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

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

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

c# - Search and Add Comment with OpenXML for Word -