Skip to content

Instantly share code, notes, and snippets.

@rtt
Created September 17, 2013 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rtt/6594003 to your computer and use it in GitHub Desktop.
Save rtt/6594003 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import sys
from collections import Counter
try:
with open(sys.argv[1], 'r') as f:
c = Counter(l.rstrip('\r\n') for l in f.readlines())
except IndexError:
print "Usage: ./count.py [infile]"
except IOError:
print 'failed to open %s' % infile
else:
for k in c:
print '"%s" occurrences: %s' % (k, c[k])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment