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 iterate through this dictionary in python

I would like to browse this dictionary more particularly the key lines

dict= {
 "comm": [
  {
  "palo": "strcc",
  "masd": "tete",
  "lignes": [
    {
      "salti": "namora",
      "fasha": "ben"
    }
   ]
 }
]
}

And to display "salti" and "fasha" I have an error

print(dict['comm']['lignes']['salti'])

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

>Solution :

"comm" and "lines" in your dictionnary are lists. So you need to add the index item you want to access :

print(dict['comm'][0]['lignes'][0]['salti'])

I think like this, it will be worked !

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