Search code examples
pythondirectorynestedextract

Extraction value from nested directories


d_3 = {'key1':'-', 'key2':{'nested_key1':'o', 'nested_key2':'x'}, 'key3':'o'}

How to extract 'x'?

Syntax for getting the value.


Solution

  • it's the same operation as getting a dictionary value, except that you need to do it twice.
    d_3['key2'] gives you the value of key2, in other words that's your nested dictionary.
    So d_3['key2']['nested_key2'] simply gives you the value of your nested_key2.

    Have a nice day ;)