Skip to content

Instantly share code, notes, and snippets.

@lucemia
Created January 23, 2016 14:32
Show Gist options
  • Save lucemia/116d323b972f05be3678 to your computer and use it in GitHub Desktop.
Save lucemia/116d323b972f05be3678 to your computer and use it in GitHub Desktop.
count.py
#!/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