Guided Project: Exploring Hacker- ERROR

Hello everyone!
I am currently working on the Guided Project: Exploring Hacker News Posts. I am getting the error “ValueError: time data ‘9’ does not match format ‘%m/%d/%Y %H:%M’” when I enter the following code:

Please help me. I am stuck.

Thanks in advance.

Hey @shaban.k!

Do you mind copy/pasting your code here? This will help others be able to run through your code faster - or copy and paste into their own environment! This will also help you get an answer much faster.

Definitely copy/paste the error as well.

Here’s a quick gif on how to format your code as well:

Hey Mary!
Here is my code.
Please help me with this

   result_list = []

for row in ask_posts:
counts_by_hour = {}
comments_by_hour ={}

for row in result_list:
    date = dt.datetime.strptime(row[0], "%m/%d/%Y %H:%M")
    time = dt.datetime.strftime(date, "%H")
    if hour in counts_by_hour:
        counts_by_hour[hour] += 1
        comments_by_hour[hour] += row[1]
        counts_by_hour[hour] = 1
        comments_by_hour[hour] = 1

Hi @shaban.k! I copied your code and I believe the error is in how result_list is created. Here is the output from result_list[:4]:

['8/16/2016 9:55', 6, '11/22/2015 13:43', 29]

You are creating a single list where the datetime (row[6]) and number of comments (row[4]) alternate. Then when you try to convert the items in the list, some of the objects are not in the datetime format and it throws up the error.

If you check out step 2 in the instructions on the page, it tells you that result_list will be “a list of lists”. Your output for result_list[4:] should look something like this:

[['8/16/2016 9:55', 6],
 ['11/22/2015 13:43', 29],
 ['5/2/2016 10:14', 1],
 ['8/2/2016 14:20', 3]]

I hope that helps! Let us know if you’re still getting stuck on this part.

1 Like

Figured it out. Thanks @april.g.

1 Like

Hi, what were you able to figure out in your solution? Was it the format in result_list or Was it inside the if statements of counts_by_hour?