How to iterate through this dictionary in python

Viewed 41

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

"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