Created
April 29, 2013 07:14
-
-
Save michaelwills/5480162 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# From http://stackoverflow.com/a/14674326/1524448 | |
import collections | |
freq = collections.Counter() | |
# sample and output | |
# line = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod' | |
# Counter({'ipsum': 1, 'amet,': 1, 'do': 1, 'sit': 1, 'eiusmod': 1, 'consectetur': 1, 'sed': 1, 'elit,': 1, 'dolor': 1, 'Lorem': 1, 'adipisicing': 1}) | |
with open(filename) as f: | |
for line in f: | |
freq.update(line.split()) | |
print freq |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment