loulett

reducer4

Nov 24th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import sys
  4.  
  5. last_key = None
  6. running_total = []
  7.  
  8. for input_line in sys.stdin:
  9.    input_line = input_line.strip()
  10.    this_key, value = input_line.split("\t", 1)
  11.  
  12.    if last_key == this_key:
  13.        running_total.append(value)
  14.    else:
  15.        if last_key:
  16.            print( "%s\t%d" % (last_key, running_total) )
  17.        running_total = value
  18.        last_key = this_key
  19.  
  20. if last_key == this_key:
  21.    print( "%s\t%d" % (last_key, running_total) )
Add Comment
Please, Sign In to add comment