Extracting Ask HN and Show HN Posts

My Code:

ask_posts = []
show_posts = []
other_posts = []

for row in hn:
    title = row[1]
    title = title.lower()
    if title.startswith('ask hn'):
        ask_posts.append(title)
    elif title.startswith('show hn'):
        show_posts.append(title)
    else:
        other_posts.append(title)

What I expected to happen: I got the correct number of posts but the way the solution coded for each title to be in lower case was done in the conditional statements. I did mine while assigning the title to a variable. Will this have an effect on my code or is this just a different way of arriving at the same solution?

I’m sorry if this doesn’t make much sense.

Thank you in advance.

Hi @rudicandaza:

Please provide a link to the mission that you are referring to. Thanks

I’m sorry! The mission is Extracting Ask HN and Show HN Posts.

Hi @rudicandaza: It should have the same effect if you do title.lower() followed by title.startswith() in the condition compared with it in the same line (as in the suggested solution) title.lower().startswith().

However, you should be appending row to ask_posts, show_posts or other_posts based on the condition instead of title because you are supposed to be appending the entire row inclusive of the title and not just only the title itself.

I have also included a screenshot of what you are appending (RED) versus what you should be appending (GREEN).

Hope this helps!

2 Likes

You are right! I totally missed that. That’s why I’ve been getting a value error in the next step! Thank you for providing clarity. Appreciate it.

No worries @rudicandaza! If you don’t mind and my answer helped to clarify your doubts, please mark my answer as the solution. Thanks!

There. Done. I’ll make sure to remember this in future posts.

1 Like

Thank you @rudicandaza. Feel free to come back to the community to clarify your doubts anytime!

Happy Pythoning!