Yassin Mohammed
Yassin Mohammed

Reputation: 25

python | I have json file : contains dictionaries inside some keys list and this list contains a dictionary

python | I have json file : contains dictionaries inside some keys list and this list contains a dictionary , how to loop through the last dictionary

"5810897312302632": {
        "post_id": "5810897312302632",
        "comments":"[{'comment_id': '9359,'comment_text':'bla bla bla'}]
}

Upvotes: 0

Views: 34

Answers (1)

Try this:

for i in my_dictionary["5810897312302632"]["comments"]:
    print(i)

It will loop over comments.

Be aware that I named your dictionary as "my_dictionary".

Edit: I create your dictionary like this:

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]

Upvotes: 1

Related Questions