Skip to content

Instantly share code, notes, and snippets.

@VioletDarkKitty
Last active October 18, 2017 21:32
Show Gist options
  • Save VioletDarkKitty/a6e1375f54b8d3247d8b8dbd5a0dc807 to your computer and use it in GitHub Desktop.
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
#!/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