Created
January 23, 2016 14:32
-
-
Save lucemia/116d323b972f05be3678 to your computer and use it in GitHub Desktop.
count.py
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
#!/usr/bin/env python | |
import sys | |
from collections import Counter | |
import re | |
from blessings import Terminal | |
term = Terminal() | |
def show(counter): | |
with term.fullscreen(): | |
for i,v in counter.most_common(20): | |
print i, '\t', v | |
c = Counter() | |
pattern = re.compile(r'([^\s]+) -> ([^\s]+)') | |
for index, line in enumerate(sys.stdin): | |
m = pattern.findall(line) | |
if m: | |
a, b = m[0] | |
else: | |
continue | |
c.update([a,b]) | |
if index % 100 == 0: | |
show(c) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment