Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import string
- words = {}
- strip = string.whitespace + string.punctuation + string.digits + "\"'"
- for line in open('shakespeare.txt'):
- for word in line.lower().split():
- word = word.strip(strip)
- if len(word) > 2:
- words[word] = words.get(word, 0) + 1
- g = open('output.txt', 'w')
- for word in sorted(words):
- g.write("'{0}' - {1} \n".format(word, words[word]))
- g.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement