Hi all!
In the Mission of Exploring Hacker News Posts, in the end of Step 5, I’m getting the error:
“Can’t convert ‘int’ object to str implicitly”
My code:
for item in result_list:
date = item[0]
date_str = dt.datetime.strptime(date, date_format)
hour = date_str.strftime("%H")
if hour not in counts_by_hour:
counts_by_hour[hour] = 1
comments_by_hour[hour] = item[1]
else:
counts_by_hour[hour] += 1
comments_by_hour[hour] += item[1]
Have tried with
comments_by_hour[hour] += int(item[1])
Still having error.
Slicing result_list[:5]:
[[‘8/16/2016 9:55’, 6],
[‘11/22/2015 13:43’, 29],
[‘5/2/2016 10:14’, 1],
[‘8/2/2016 14:20’, 3],
[‘10/15/2015 16:38’, 17]] - I do have correct number of comments
Paste output/error here
TypeErrorTraceback (most recent call last)
in ()
8 else:
9 counts_by_hour[hour] += 1
—> 10 comments_by_hour[hour] += item[1]
TypeError: Can’t convert ‘int’ object to str implicitly
And my dictionary comments_by_hour looks like:
{‘00’: ‘///////////////////////////////////////////////////////’,
‘01’: ‘////////////////////////////////////////////////////////////’,
‘02’: ‘//////////////////////////////////////////////////////////’,
‘03’: ‘//////////////////////////////////////////////////////’,
etc
I’d appreciate your help!My file is attached.
[Basics (1).ipynb|attachment]
(upload://onhdxKzrXUlRzeaGjvAxFA1YGYq.ipynb) (16.7 KB)