Home > Net >  How to iterate through this dictionary in python
How to iterate through this dictionary in python

Time:09-15

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'])

CodePudding user response:

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

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