Last active
December 17, 2015 06:09
-
-
Save fulmicoton/5563104 to your computer and use it in GitHub Desktop.
Computes the 10 most frequent token from stdin or a couple of files.
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
import re | |
import fileinput | |
from collections import Counter | |
token_ptn = re.compile("[^\w]+") | |
word_count = Counter() | |
for line in fileinput.input(): | |
for token in token_ptn.split(line): | |
if token != "": | |
word_count[token] += 1 | |
for (k,v) in word_count.most_common(10): | |
print k, v |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment