Guided project 2 # Calculating the Average Number of Comments for Ask HN and Show HN Posts

Hello, I’m blocking and I don’t undersant why, anyone out there can help me please ?

My code is:

total_ask_comments = 0

for post in ask_posts:
** total_ask_comments += int(post[4])**


avg_ask_comments = total_ask_comments / len(ask_posts)
print(avg_ask_comments)

And I’m getting the error:
ValueError: invalid literal for int() with base 10: 'h’

If I understand well, there is an ‘h’ in the middle of my numbers string so I cannot change it to ‘int’, is it ??

How can I fix it please? Thanks for your help!

Based on what you’ve shared, I feel like there may be a discrepancy from a previous step. Have you reviewed the data when you separated “Show HN” from “Ask HN” posts?

Thanks for you reply Aaron, evrything before is exacly the same as the solution porject :confused:

What are your lengths for show posts, ask posts, and other posts?

Something you can try would be creating a list of lists of the comment counts only, and then iterate through that list of lists and search for the “h” like this:

filter_list = []

for post in comments_counts:
if “h” in post:
filter_list.append(post)

Doing something like this should help you identify which post has the “h” within the comment count.

Ahh thanks Aaron, I’ll try that. Then all I have to do is delete it, isn’t it ? Thanks!

Correct! Let me know how this works.