Skip to content

Instantly share code, notes, and snippets.

@mmas
Created July 5, 2017 00:03
Show Gist options
  • Save mmas/b7286d20d5f1475f13d2c0e18b90aa81 to your computer and use it in GitHub Desktop.
Save mmas/b7286d20d5f1475f13d2c0e18b90aa81 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
last_k = None
last_v = 0
for line in sys.stdin:
k, v = line.strip().split('\t')
v = int(v)
if last_k == k:
last_v += v
else:
if last_k:
print '%s\t%s' % (last_k, last_v)
last_k = k
last_v = v
if last_k == k:
print '%s\t%s' % (last_k, last_v)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment