Hackers News Post Project

Mission Link: https://app.dataquest.io/m/356/guided-project%3A-exploring-hacker-news-posts/3/extracting-ask-hn-and-show-hn-posts

Your Code:
ask_posts = []
show_posts = []
other_posts = []
for row in hn:
title = row[1]
if title.startswith('ask hn'):
elif title.startswith('show hn'):
Error: ask_posts and show_posts returning empty list

Question: Please, what am I doing wrong? Am getting empty list after appending title for each conditions


Hi Owojori. I think you may have missed this part of the instructions:

If the lowercase version of title starts with ask hn

Unless the title already starts exactly with ask hn (compared to “Ask HN” or “ask HN” with varying capital letters), it won’t get appended to the list. You’ll need to include a line of code that turns the title into an all lowercase version so that then it can check for the start of the title.

I hope that helps.

1 Like

If I get you right.
You mean I should check for startwith('ask HN') in another line of code??

1 Like

There’s too many possible variations to check all of them. It’s a lot easier to just make the entire title lowercase using the string.lower() method.

title = title.lower()
1 Like

I get

Thanks a bunch

My Code is working now :grinning: :grinning: :grinning:


fell into same trap, thanks a lot for reaching here before me :grinning: :grinning:

1 Like