smishlayev

reducer.py

Jun 10th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import sys
  4.  
  5. last_id = None
  6. last_value = 0
  7. for line in sys.stdin:
  8.     (date, code, value) = line.split("\t")
  9.     if (date, code) == last_id:
  10.         last_value += value
  11.     else:
  12.         if last_id:
  13.             print("{0},{1},{2}".format(last_id[0], last_id[1], last_value)
  14.         last_id = (date, code)
  15.         last_value = value
  16.  
  17. if (date, code) == last_id:
  18.     print("{0},{1},{2}".format(last_id[0], last_id[1], last_value)
Advertisement
Add Comment
Please, Sign In to add comment