Skip to content

Instantly share code, notes, and snippets.

@samdphillips
Created January 13, 2015 20:52
Show Gist options
  • Save samdphillips/f0833c66d59dec32ad6b to your computer and use it in GitHub Desktop.
Save samdphillips/f0833c66d59dec32ad6b to your computer and use it in GitHub Desktop.
import sys
d = {}
for line in sys.stdin:
key,value = line.strip().split('\t')
count, running_value = d.get(key, [0, 0])
d[key] = (count + 1, running_value + float(value))
for k,v in d.iteritems():
print '%s\t%.2f' % (k, v[1] / v[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment