Mercurial > hg > python
changeset 51:44fea514ca45
foo
author | Henry S. Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Sun, 19 Feb 2023 16:44:06 +0000 |
parents | d335ca1fb71b |
children | 10f17205908f |
files | char_hist.py |
diffstat | 1 files changed, 43 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/char_hist.py Sun Feb 19 16:44:06 2023 +0000 @@ -0,0 +1,43 @@ +#!/usr/bin/python3 +import sys + +h={} +mc=0 +nonAscii=0 + +if len(sys.argv)>1: + showMe=[int(a) for a in sys.argv[1:]] +else: + showMe=[] + +def main(): + global h, mc, nonAscii, showMe + for l in sys.stdin: + na=0 + sm=0 + for c in l: + h[c]=h.get(c,0)+1 + o=ord(c) + sm+=(o in showMe) + na+=(o>127) + if o>mc: + mc=o + if na>0: + nonAscii+=1 + if sm>0: + sys.stderr.write(l) + + for i in range(128): + print(i,chr(i),h.get(chr(i),0)) + print('-------') + if nonAscii>0: + print("%s lines with one or more non-ascii characters"%nonAscii) + for i in range(128,mc+1): + c=chr(i) + if c in h: + print(i,c,h[c]) + +if __name__ == '__main__': + main() + +