Skip to content

Instantly share code, notes, and snippets.

Last active January 28, 2022 19:34
What would you like to do?
sum and count columns from stdin, because I'm no good at awk
import sys
d = {}
for line in sys.stdin:
adds, dels, path = line.rstrip().split('\t')
if path in d:
d[path]['adds'] += int(adds)
d[path]['dels'] += int(dels)
d[path]['count'] += 1
d[path] = {'adds': int(adds), 'dels': int(dels), 'count': 1}
for path, vals in d.items():
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment