Skip to content

Instantly share code, notes, and snippets.

@andresmachado
Created March 15, 2016 20:25
Show Gist options
  • Save andresmachado/714d5e7eca9b56d8e8e5 to your computer and use it in GitHub Desktop.
Save andresmachado/714d5e7eca9b56d8e8e5 to your computer and use it in GitHub Desktop.
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