Mercurial > hg > python
view char_hist.py @ 74:0245bc07f16c simple
try to simplify Rows/Cols (do without?) by hiving off the run-counts copletely
| author | Henry Thompson <ht@markup.co.uk> |
|---|---|
| date | Sat, 09 Aug 2025 15:59:19 -0400 |
| parents | 44fea514ca45 |
| children |
line wrap: on
line source
#!/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()
