110-5 API finding most upvoted comment

Screen Link:

My Code:

for comment in comments:
        for reply in comment["data"]["children"]:

What I expected to happen: it should find most upvoted comment, and it actualy finds it I think it is 55.

What actually happened: Systems says it is 9. So what is the correct answer really , 55 or 9.

Replace this line with the output/error

The correct answer is 9. You should be looking for the children key in the second item in the list to find the list of comments. The mission screen says: " Querying the comments endpoint at /r/{subreddit}/comments/{article} returns a list. The first item in the list contains information about the post, and the second item contains information about the comments." The code I wrote goes like:

comments_list = comments[1]["data"]["children"]

most_upvotes_comment = 0
most_upvoted_comment = ""

for comment in comments_list:
    comment_data = comment["data"]
    comment_id = comment_data["id"]
    comment_ups = comment_data["ups"]
    if comment_ups >= most_upvotes_comment:
        most_upvoted_comment = comment_id
        most_upvotes_comment = comment_ups

As you can see, I specified that I wanted to loop through the list of comments in the comments endpoint by using index number 1 in the first line.

1 Like