Skip to content

Instantly share code, notes, and snippets.

@iktakahiro
Last active January 1, 2016 18:29
Show Gist options
  • Save iktakahiro/8184130 to your computer and use it in GitHub Desktop.
Save iktakahiro/8184130 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'Takahiro Ikeuchi'
import sys
import re
from collections import defaultdict
def main():
line = sys.stdin.readline()
sum_dict = defaultdict(int)
try:
while line:
key, value = line.split('\t')
value = re.sub('\n', '', value)
sum_dict[key] += int(value)
line = sys.stdin.readline()
for key, value in sum_dict.items():
print key + '\t' + str(value)
except "end of file":
return None
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment