Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to extract 'hello' from the following nested dictionary using indexing?

How can I extract hello from the code using indexing?

I_say = {'stairs_1':[1, 'two', {'stairs_2':['Close to the door', {'in the door':['one', 2, ['hello']]}]}]}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I completely understand why this question was downvoted. It’s just basic knowledge that a Python tutorial would help you with.

Nevertheless, it would help you immensely if you’d reformat your code and make it more readable.

{
  "stairs_1":[
    1,
    "two",
    {
      "stairs_2":[
        "Close to the door",
        {
          "in the door":[
            "one",
            2,
            [
              "hello"
            ]
          ]
        }
      ]
    }
  ]
}

After looking at this code, you can see that the first level is a dictionary with a key stairs_1, its value is a list of three values.

The third value is a dictionary that contains just one element. Again, stairs_2 is the key and the value is a list, this time of two elements.

The second element is a dictionary that contains one element, its key is in the door and the value is a list.

The list contains three elements, while the third one is a list with a single element – your "hello" string.

So the answer is I_say['stairs_1'][2]['stairs_2'][1]['in the door'][2][0]

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading