Lab 13: More on Strings and Parsing
Create a program which finds the most popular 100 words in webpages.
Your program should take one input, which is the filename of the webpage (already downloaded) which you'll look at. Then, read in the entire contents of the file (read() method), and split it into words (split() method). Once you have a list of words, iterate through this list and keep count of how many times each word occurs.
To keep count, use a dictionary. We haven't talked about these much, but here's a demonstration of what you need:
word_list = {}
# You need a for loop here
if word in word_list:
word_list[word] += 1
else:
word_list[word] = 1
After word_list is completed, you'll need to count the most common words. Here is a list that will return a sorted list:
sorted(word_list.items(), key=lambda x : x[1])