Skip to content

Instantly share code, notes, and snippets.

@johno
Created June 20, 2013 15:50
Show Gist options
  • Save johno/5823990 to your computer and use it in GitHub Desktop.
Save johno/5823990 to your computer and use it in GitHub Desktop.
import re; import sys
from collections import defaultdict
try:
file = open(sys.argv[1])
except:
print "Usage: python wf.py <path_to_file/filename>"
word_freq = defaultdict(int)
for line in file:
words = re.findall('\w+', line.strip())
for word in words:
word_freq[word.lower()] += 1
for word, freq in sorted(word_freq.iteritems()):
print word, freq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment