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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -