Hi fellow glorious Dataquest Learners!
I’m in the Mission 5 of Exploring Hacker News Posts, in the end of Step 5, I probably do it right (generating dictionaries of comments and counts). However, I don’t fully understand what line 8 said about the arguments.
- Use the string we want to parse as the first argument and a string that specifies the format as the second argument.
All I did is following code:
for row in result_list:
time = row[0]
date_time = dt.datetime.strptime(time, “%m/%d/%Y %H:%M”)
hour = date_time.strftime("%H")
if hour not in counts_by_hour:
counts_by_hour[hour] = 1
comments_by_hour[hour] = int(row[1])
else:
counts_by_hour[hour] += 1
comments_by_hour[hour] += int(row[1])
Can someone explain it to me, thanks.
counts_by_hour = {}
{'13': 85, '14': 107, '15': 116, '20': 80, '12': 73, '23': 68, '11': 58, '21': 109, '03': 54, '16': 108, '19': 110, '18': 109, '08': 48, '07': 34, '22': 71, '00': 55, '04': 47, '01': 60, '05': 46, '09': 45, '02': 58, '10': 59, '17': 100, '06': 44}
comments_by_hour = {}
{'13': 1253, '14': 1416, '15': 4477, '20': 1722, '12': 687, '23': 543, '11': 641, '21': 1745, '03': 421, '16': 1814, '19': 1188, '18': 1439, '08': 492, '07': 267, '22': 479, '00': 447, '04': 337, '01': 683, '05': 464, '09': 251, '02': 1381, '10': 793, '17': 1146, '06': 397}