Skip to content

Instantly share code, notes, and snippets.

@bobmurder
Created November 12, 2012 03:17
Show Gist options
  • Select an option

  • Save bobmurder/4057297 to your computer and use it in GitHub Desktop.

Select an option

Save bobmurder/4057297 to your computer and use it in GitHub Desktop.
from collections import defaultdict
with open("names") as f:
names = [name.strip() for name in f]
counts = defaultdict(int)
for name in names:
counts[name] += 1
final_tally = [(k, v) for k, v in counts.items()]
final_tally = sorted(final_tally, key=lambda x: x[1])
final_tally.reverse()
top = ["%s: %s" % (final_tally[n][0].strip("<> "), final_tally[n][1]) for n in range(10)]
print '; '.join(top)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment