Mercurial > hg > python
comparison char_hist.py @ 51:44fea514ca45
foo
author | Henry S. Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Sun, 19 Feb 2023 16:44:06 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
50:d335ca1fb71b | 51:44fea514ca45 |
---|---|
1 #!/usr/bin/python3 | |
2 import sys | |
3 | |
4 h={} | |
5 mc=0 | |
6 nonAscii=0 | |
7 | |
8 if len(sys.argv)>1: | |
9 showMe=[int(a) for a in sys.argv[1:]] | |
10 else: | |
11 showMe=[] | |
12 | |
13 def main(): | |
14 global h, mc, nonAscii, showMe | |
15 for l in sys.stdin: | |
16 na=0 | |
17 sm=0 | |
18 for c in l: | |
19 h[c]=h.get(c,0)+1 | |
20 o=ord(c) | |
21 sm+=(o in showMe) | |
22 na+=(o>127) | |
23 if o>mc: | |
24 mc=o | |
25 if na>0: | |
26 nonAscii+=1 | |
27 if sm>0: | |
28 sys.stderr.write(l) | |
29 | |
30 for i in range(128): | |
31 print(i,chr(i),h.get(chr(i),0)) | |
32 print('-------') | |
33 if nonAscii>0: | |
34 print("%s lines with one or more non-ascii characters"%nonAscii) | |
35 for i in range(128,mc+1): | |
36 c=chr(i) | |
37 if c in h: | |
38 print(i,c,h[c]) | |
39 | |
40 if __name__ == '__main__': | |
41 main() | |
42 | |
43 |