简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM