Screen Link: https://app.dataquest.io/m/356/guided-project%3A-exploring-hacker-news-posts/3/extracting-ask-hn-and-show-hn-posts
header = hn
hn = hn[1:]
ask_posts = 
show_posts = 
other_posts = 
for row in hn:
title = row
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', 'https://github.com/jmcarp/robobrowser', '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.
Are you absolutely sure that
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 -
[‘11680777’, ‘RoboBrowser: Your friendly neighborhood web scraper’, ‘https://github.com/jmcarp/robobrowser’, ‘182’, ‘58’, ‘pmoriarty’, ‘5/12/2016 1:43’]
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.
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.
Can you point out which values you are talking about?
- Which values are the same?
- What did you expect the values to be instead?
These are the values I was referring to:
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.
I have just gone over my work, figured where the confusion was, and now have a better understanding of how the code should be.
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?
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.