GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — example-code-2e/04-text-byte/categories.py at master · FerMatPy/example-code-2e Expand file tree/ Copy pathcategories.pyMore file actions 45 lines (37 loc) · 1.08 KB / Copy pathcategories.pyFile metadata and controls45 lines (37 loc) · 1.08 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 import sys import collections from unicodedata import category def category_stats(): counts = collections.Counter() firsts = {} for code in range(sys.maxunicode + 1): char = chr(code) cat = category(char) if cat not in counts: firsts[cat] = char counts[cat] += 1 return counts, firsts def category_scan(desired): for code in range(sys.maxunicode + 1): char = chr(code) if category(char) == desired: yield char def main(args): count = 0 if len(args) == 2: for char in category_scan(args[1]): print(char, end=' ') count += 1 if count > 200: break print() print(count, 'characters shown') else: counts, firsts = category_stats() for i, (cat, count) in enumerate(counts.most_common(), 1): first = firsts[cat] if cat == 'Cs': first = f'(surrogate U+{ord(first):04X})' print(f'{i:2} {count:6} {cat} {first}') if __name__ == '__main__': main(sys.argv) |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |