#!/usr/bin/env python3; ############################################################################### # This program reads characters from STDIN and then computes a frequency table. # # Copyright © 2020 Richard Lesh. All rights reserved. ############################################################################### import Utils import re import sys # Begin Main totalCount = 0 countTable = {} c = Utils.getchar(sys.stdin) while c != None : if (not (c in countTable.keys())) : countTable[c] = 1 else : countTable[c] += 1 totalCount += 1 c = Utils.getchar(sys.stdin) print("Hex\tChar\tCount\tFreq") sortedKeys = sorted(countTable.keys(), key = int) for x in sortedKeys : freq = countTable[x] / totalCount if (re.match("^[\x00-\x1f\x7f\u0080-\u009f]",chr(x))) : print("{0:05x}\t0x{0:x}\t{1:d}\t{2:.4f}".format(x, countTable[x], freq)) else : print("{0:05x}\t{1:c}\t{2:d}\t{3:.4f}".format(x, x, countTable[x], freq))