Exploring Hacker News Guided Project

Hello everyone.

I am new in programming with Python and I have just followed the steps to complete Hacker News Guided Project. And I am delighted to share my code publicly.

Screen Link:

I have also attached the notebook code here in case the screen link fails.

I need the community to help me review and criticize the code. What I did well and what I didn’t do well.
Thanks and best regards.

My Code:

hacker_news_guided_project.ipynb (17.5 KB)

HI Ogahi. The attached notebook was exactly what we needed to see (the link just shows me my own project). Thanks for sharing!

Everything in the code looked good up until we get the averages by hour. The numbers didn’t look right, so I went further up into the code to see what might have gone wrong. The problem seems to be in the cell where result_list and the comments_by_hour and counts_by_hour dictionaries are created. I copied it below and added some comments to help you troubleshoot. The main problem seems to be the use of ask_comments_no. This was a variable used in a previous loop, so its value is stuck at 2.

import datetime as dt 

result_list = []

for row in ask_posts:
    created_at = row[6]
    result_list.append([created_at, ask_comments_no])   #ask_comments_no is always 2 from last loop
counts_by_hour = {}
comments_by_hour = {}
date_format = "%m/%d/%Y %H:%M"

for row in result_list:
    comments_date = row[0]
    comments_hour = dt.datetime.strptime(comments_date, date_format).strftime("%H")
    if comments_hour not in counts_by_hour:
        counts_by_hour[comments_hour] = 1
        comments_by_hour[comments_hour] = ask_comments_no    #ask_comments_no is always 2 from previous loop
        comments_by_hour[comments_hour] += 1   #should be counts_by_hour
        comments_by_hour[comments_hour] += ask_comments_no  #ask_comments_no is always 2 from previous loop

I hope that helps give you some direction for how to fix the code. Let us know if you update your project so we can give it a second look!


Thank you for your careful review, @april.g. Following the guide you provided, I was able to figure out some errors and made some edits to my code for Hacker News Guided Project.
Kindly see the attachment for another review.
Thank you all.

hacker_news_guided_project.ipynb (18.3 KB)

Click here to view the jupyter notebook file in a new tab

Great job following up and figuring out how to fix the errors in the code! The results look much better now. :smiley:

1 Like

Thanks for your support, @april.g. Gracias!