#!/usr/bin/python """Ground-truth word frequency program. To verify that my C implementations produce the intended output, I wrote this slower but very likely correct implementation in Python. """ import sys def main(): freqs = {} for line in sys.stdin: for word in line.split(): if word not in freqs: freqs[word] = 0 freqs[word] += 1 for word in sorted(freqs.keys()): print "%8d %s" % (freqs[word], word) if __name__ == '__main__': main()