简体   繁体   English

如何在 python 中遍历此字典

[英]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并显示“salti”和“fasha”我有一个错误

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

"comm" and "lines" in your dictionary are lists.字典中的“comm”和“lines”是列表。 So you need to add the index item you want to access:所以需要添加要访问的索引项:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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