Mercurial > hg > lib > markup
annotate python/sumUC.py @ 3:870e13483642
sum outputs from multiple uniq -c, maybe?
author | Henry S. Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Tue, 25 May 2021 14:00:47 -0400 |
parents | |
children |
rev | line source |
---|---|
3
870e13483642
sum outputs from multiple uniq -c, maybe?
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
1 #!/usr/bin/python |
870e13483642
sum outputs from multiple uniq -c, maybe?
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
2 import sys |
870e13483642
sum outputs from multiple uniq -c, maybe?
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
3 ss={} |
870e13483642
sum outputs from multiple uniq -c, maybe?
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
4 n=0 |
870e13483642
sum outputs from multiple uniq -c, maybe?
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
5 for l in sys.stdin: |
870e13483642
sum outputs from multiple uniq -c, maybe?
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
6 (count,key)=l.strip().split() |
870e13483642
sum outputs from multiple uniq -c, maybe?
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
7 ss[key]=ss.get(key,0)+int(count) |
870e13483642
sum outputs from multiple uniq -c, maybe?
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
8 n+=1 |
870e13483642
sum outputs from multiple uniq -c, maybe?
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
9 tt=0 |
870e13483642
sum outputs from multiple uniq -c, maybe?
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
10 for (key,total) in ss.items(): |
870e13483642
sum outputs from multiple uniq -c, maybe?
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
11 tt+=total |
870e13483642
sum outputs from multiple uniq -c, maybe?
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
12 print "%s\t%s"%(key,total) |
870e13483642
sum outputs from multiple uniq -c, maybe?
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
13 print >>sys.stderr,"%s vs. %s"%(n,tt) |