view master/src/wecu/sac_reducer.py @ 58:a3edba8dab11

move to right place in tree
author Henry S. Thompson <ht@markup.co.uk>
date Thu, 28 May 2020 09:56:42 +0000
parents master/wecu/sac_reducer.py@ac1a20e627a9
children 5fdca5baa4e9
line wrap: on
line source

#!/usr/bin/python

import sys
from collections import defaultdict

if sys.argv[0] == 'by-file':
    # Show results by file
    for line in sys.stdin:
        print(line.strip())
else:
    # Aggregate results
    counters = defaultdict(int)

    for line in sys.stdin:
        try:
            line = line.strip().split('\t')
            k = line[0] 
            v = line[1]
        except:
            continue

        counters[k] += int(v)

    for k in counters:
        print("{}\t{}".format(k, counters[k]))