-
-
Save AndersonFirmino/ab981182cef669a56098 to your computer and use it in GitHub Desktop.
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
import sys | |
def count_words(text_file): | |
file = open(textfile,'r+') | |
word_list = {} | |
for word in file.read().split(): | |
if word not in word_list: | |
word_list[word] = 1 | |
else: | |
word_list[word] += 1 | |
return word_list | |
textfile = sys.argv[1] | |
list_of_words = count_words(textfile) | |
for word in sorted(list_of_words, key=list_of_words.get, reverse=True): | |
print word, list_of_words[word] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment