#!/usr/bin/python """Count the frequency of different inputs on stdin. A replacement for | sort | uniq -c | sort -nr By Nelson Minar , placed in the public domain.""" import sys # Count up all the lines data = {} total = 0 for l in sys.stdin: data[l] = data.setdefault(l, 0) + 1 total += 1 # Sort the data by frequency counts = zip(data.values(), data.keys()) counts.sort() counts.reverse() # Print out the bins for count, item in counts: fract = "%.4f" % (float(count) / total) if fract[0] == '0': fract = fract[1:] print "%7d %s %s" % (count, fract, item),