Why is only the 2nd element of the list of dictionaries used?

i just don’t understand how:

comments_list = comments[1][“data”][“children”]

returns only the comments as a list from the ‘comments’ json list of dictionaries. Wouldn’t it just return the 2nd element?

Understanding the data from json .get requests are a nightmare in general so is there any resources i can look up to make further sense of the most common formats that gets dumped from API get requests?

1 Like

Hello @alp.f.alptekin, welcome to the community!

First, I ask you to always paste the link for the mission in your topic as it makes it easier for those trying to answer your question. You can see how to do this and more in the Technical Question Guidelines.


Answering your question:

comments is a list full of dictionaries. Therefore, comments[1] is a dictionary. This dictionary contains 2 keys: data and kind. You are accessing the data key. The value represented by this key is also a dictionary from which you are accessing the children key. With this said:

It does return only the second element. But this element is a dictionary containing all the comments the post has received. The comments are stored in the children key of the dictionary that is stored in the data key of the dictionary that is the second element of comments list. Confusing, yes, I know.

Also, keep in mind that the comments list refers to a single Reddit post.

4 Likes

ohhhhhh.

ok thank you makes a lot more sense now. Will try to stick to the submission guidelines more strictly in the future.

2 Likes

Hi @otavios.s,

Its bit confusing to understand, but i want to know what is the difference between. Both are elements in list stored as dictionary.

comments[1][“data”][“children”]
&
comments[0][“data”][“children”]

What being addressed in comments[0] ? I see comments[1] is pretty lengthy compared to comments[0[

1 Like

Hello @alihabib.

Could you share the screen link, please? This was a while ago and do not remember which mission it was exactly.

Hi @otavios.s This is the one 110/5. Working with Reddit API

@alihabib: Please adhere to these guidelines