Guided Project: Hacker News Posts -- ask_posts, show_posts

Screen Link:

My Code:

header = hn[0]
hn = hn[1:]
print (hn[:5])

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

for row in hn:
    title = row[1]
    title = title.lower()
    if title.startswith('ask hn'):

    elif title.startswith('show hn'):

print('Number of posts that start with ask_hn:', len(ask_posts))
print('Number of posts that start with show_hn:', len(show_posts))
print('Number of other post types:', len(other_posts))


What I expected to happen:

I visited the community a few minutes ago because I was getting the wrong output for this code.
Then I saw the solution you gave a fellow DQ learner and saw that the significant difference between my code and his was that I passed [ask_posts] into the print() function as opposed to passing it in without the brackets.

I fixed only that and expected a wrong output seeing that I used ‘title’ instead of ‘row’.

What actually happened:

Number of posts that start with ask_hn: 1744
Number of posts that start with show_hn: 1162
Number of other post types: 17194
['11680777', 'RoboBrowser: Your friendly neighborhood web scraper', '', '182', '58', 'pmoriarty', '5/12/2016 1:43']

Meanwhile, I still got this output when I replaced ‘title’ with ‘row’

I’ll appreciate any help understanding why this is so.

Thank you.

1 Like

Are you absolutely sure that print(title) and print(row) print out the exact same result? And that you are running the Cells in the correct order without any additional changes?

Because I tried your code, and I get the output as expected -

For print(row)

[‘11680777’, ‘RoboBrowser: Your friendly neighborhood web scraper’, ‘’, ‘182’, ‘58’, ‘pmoriarty’, ‘5/12/2016 1:43’]

For print(title)

robobrowser: your friendly neighborhood web scraper

Let me know if I misunderstood your question or not. But, based on your description it seems that you are asking about why the output from those two print statements is the same.

1 Like

Hi @the_doctor.

I just ran it again and I’m getting the same result as what you have posted here.

However, my question is about the values – The values are the same in both cases.

I wasn’t getting the correct values when I initially used (title).

Thank you for offering to help.

1 Like

Can you point out which values you are talking about?

  • Which values are the same?
  • What did you expect the values to be instead?
1 Like

These are the values I was referring to:

1 Like

I think this is leading to some confusion because you haven’t pointed out what your code was before you made changes to it.

If you can share that, then we can narrow it down.

1 Like

I have just gone over my work, figured where the confusion was, and now have a better understanding of how the code should be.

Thank you.

1 Like

I have similar issue like yours now. I’m yet to figure out where the issue is. oops!

I’ve gotten my mistake. I had a typo. I got the results up there. Are you saying those results aren’t correct?

Hi @samuelabidemi2.

I just saw this.

Glad to know you figured it out.

The issue I had was with appending ‘title’ instead of ‘row’(I missed this in the instructions).
My initial confusion was with how I was getting the same numerical values (number of posts) in both instances.

But then again, I was appending just the title of the post instead of the entire row.

Hope this is clear enough?

Yeah. Thanks. I really appreciate your reply.