example multi level dict in python

Python -- Posted on May 5, 2023

  1. my_dict is the main dictionary that contains two key-value pairs.
  2. The keys in the my_dict are level1_key1 and level1_key2.
  3. The values corresponding to each key in my_dict are also dictionaries themselves.
  4. Each inner dictionary contains two key-value pairs.
  5. For the level1_key1 inner dictionary, the keys are level2_key1 and level2_key2, and the corresponding values are "value1" and "value2" respectively.
  6. For the level1_key2 inner dictionary, the keys are level2_key3 and level2_key4, and the corresponding values are "value3" and "value4" respectively.

So, my_dict has two levels of nested dictionaries with multiple key-value pairs. This nested structure allows you to organize data in a hierarchical manner, making it easy to access and manage related information.

 

              
                my_dict = {
    "level1_key1": {
        "level2_key1": "value1",
        "level2_key2": "value2"
    },
    "level1_key2": {
        "level2_key3": "value3",
        "level2_key4": "value4"
    }
}
                  
   
            

Related Posts