![](/img/trans.png)
[英]Flatten a list of dictionary that contains a list of dictionaries in python
[英]python | I have json file : contains dictionaries inside some keys list and this list contains a dictionary
python | 我有 json 文件:在一些鍵列表中包含字典,這個列表包含一個字典,如何遍歷最后一個字典
"5810897312302632": {
"post_id": "5810897312302632",
"comments":"[{'comment_id': '9359,'comment_text':'bla bla bla'}]
}
嘗試這個:
for i in my_dictionary["5810897312302632"]["comments"]:
print(i)
它將遍歷comments
。
請注意,我將您的字典命名為“my_dictionary”。
編輯:我這樣創建你的字典:
inside_dictionary = {}
inside_dictionary["comment_id"] = '9359'
inside_dictionary["comment_text"] = 'bla bla bla'
my_dictionary = {}
my_dictionary["5810897312302632"] = {}
my_dictionary["5810897312302632"]["post_id"] = "5810897312302632"
my_dictionary["5810897312302632"]["comments"] = [inside_dictionary]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.