header = hn hn = hn[1:] print(header) print (hn[:5]) ask_posts =  show_posts =  other_posts =  for row in hn: title = row 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) 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)) print(row)
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.