Skip to content

Instantly share code, notes, and snippets.

@scottt
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save scottt/79fdfe6dec058f3d7ce2 to your computer and use it in GitHub Desktop.

Select an option

Save scottt/79fdfe6dec058f3d7ce2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python2
from __future__ import print_function
import sys
import collections
d = collections.defaultdict(int)
fin = sys.stdin
n = int(fin.readline())
for i in xrange(n):
word = fin.readline().strip()
d[word] += 1
freq_word_pairs = [ (-x[1], x[0]) for x in d.items() ]
freq_word_pairs.sort()
k = int(fin.readline())
for i in xrange(k):
print(freq_word_pairs[i][1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment