Last active
October 18, 2017 21:32
-
-
Save VioletDarkKitty/a6e1375f54b8d3247d8b8dbd5a0dc807 to your computer and use it in GitHub Desktop.
Print most used words. Change the filename 'input' to another one to load files. Plain text only
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
content = "" | |
with open('input', 'r') as content_file: | |
content = content_file.read() | |
words = {} | |
for word in content.split(): | |
if word in words: | |
words[word] = words[word] + 1 | |
else: | |
words[word] = 1 | |
for count, word in sorted( ((v,k) for k,v in words.items()), reverse=True): | |
print ("%s: %d" % (word, count)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment