Guided project: Exploring hacker news posts - Is my code correct?

Screen Link:
https://app.dataquest.io/m/404/guided-project%3A-exploring-hacker-news-posts/5/finding-the-amount-of-ask-posts-and-comments-by-hour-created

My Code:

result_list = []
for row in ask_posts:
    date = row[6]
    comments = int(row[4])
    result_list.append([date, comments])

counts_by_hour = {}
comments_by_hour = {}

for row in result_list:
    date = row[0].split(' ')[0]
    hour = row[0].split(' ')[1]
    date_dt = dt.datetime.strptime(hour, "%H:%M")
    time_dt = dt.datetime.strftime(date_dt,"%H" )
    if time_dt not in counts_by_hour:
        counts_by_hour[time_dt] = 1
        comments_by_hour[time_dt] = row[1]
    else:
        counts_by_hour[time_dt] += 1
        comments_by_hour[time_dt] += row[1]```

What I expected to happen:
Hi there, Im not getting an error but Im not sure if Im following the instructions correctly. Is my solution correct? I wonder about how Im using `strptime` and `strftime` and how I broke down the `date` and `hour` variables at the beginning of the for loop.

Thanks

Replace this line with the output/error

No error.
<!--Enter other details below: -->

Hi there,

I’m just done with the project and this solution looks right to me. Of course I’m still learning, too, so maybe I oversee something. Only thing I see is that the date variable seems redundant.

You can also compare to the official solution, which you can access by clicking on the key symbol on the top of the jupyter notebook. Here is the solution for this task:
https://github.com/dataquestio/solutions/blob/master/Mission356Solutions.ipynb

2 Likes

Awesome thanks for that pointer.