Screen Link:
https://app.dataquest.io/m/356/guided-project%3A-exploring-hacker-news-posts/3/extracting-ask-hn-and-show-hn-posts
My Code:
from csv import reader
opened_file = open('hacker_news.csv')
read_file = reader(opened_file)
hn = list(read_file)
hn = hn[:5]
print(hn)
# in order to isolate the headers we must extract:
headers = hn[0]
hn = hn[1:]
print(headers)
# headers are isolated and now we will display the first 5 rows
print(hn[:5])
# Create three empty lists
ask_posts = []
show_posts = []
other_posts = []
#loop Through data given title at index of 1 and append data
for row in hn:
title = row[1]
if title.lower().startswith('ask hn'):
ask_posts.append(row)
elif title.lower().startswith('show hn'):
show_posts.append(row)
else:
other_posts.append(row)
# Check number of posts in each
print('The number of ask posts equals', len(ask_posts))
print('The number of show posts equals', len(show_posts))
print('The number of other posts equals', len(other_posts))
What I expected to happen:
The correct number of ask_posts, show_posts and other_posts
What actually happened:
The number of ask posts equals 0
The number of show posts equals 0
The number of other posts equals 4
Any help will be greatly appreciated, Thank you!