Skip to content

Instantly share code, notes, and snippets.

@rndD
Last active December 31, 2015 08:39
Show Gist options
  • Save rndD/7962030 to your computer and use it in GitHub Desktop.
Save rndD/7962030 to your computer and use it in GitHub Desktop.
count words in file
import re
with open('simple.txt', 'r') as f:
words = re.findall(r'\w+', f.read())
for w in sorted(list(set([(w, words.count(w)) for w in words])), key=lambda x: x[1]):
print "%20s -> %d" % w
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment