Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 28 lines (22 sloc) 687 Bytes
#!/usr/bin/env python
import sys
# maps words to their counts
word2count = {}
for line in sys.stdin:
# remove leading and trailing whitespace
line = line.strip()
# parse the input we got from
word, count = line.split('\t', 1)
# convert count (currently a string) to int
count = int(count)
word2count[word] = word2count.get(word, 0) + count
except ValueError:
# count was not a number, so silently
# ignore/discard this line
# sort the words lexigraphically;
sorted_word2count = word2count.items()
for word, count in sorted_word2count:
print '%s\t%s'% (word, count)