Created
March 19, 2014 14:40
-
-
Save natbusa/9643054 to your computer and use it in GitHub Desktop.
word count: python
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
#readin and filter | |
txt = [c for c in open('lorem.txt').read().lower() if c.isalpha() or c==' '] | |
#groupBy in a dictionary | |
wc = dict() | |
for w in ''.join(txt).split(): | |
wc[w] = wc.setdefault(w, 0) + 1 | |
#output | |
for k,v in wc.iteritems(): | |
print('{1} {0}'.format(k,v)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment