#!/usr/bin/python3 # # This program reads a text file from the standard input, and prints # the list of all characters present in the input followed by the # number of times the character appears in the input. The output is # sorted in reverse order of frequency, from the highest to the lowest # frequency count. # import sys freq = {} for line in sys.stdin: for c in line: if c in freq: freq[c] = freq[c] + 1 else: freq[c] = 1 sorted_freq = list(freq.items()) for i in range(1,len(sorted_freq)): j = i while j > 0 and sorted_freq[j][1] > sorted_freq[j-1][1]: sorted_freq[j], sorted_freq[j-1] = sorted_freq[j-1], sorted_freq[j] j = j - 1 for c, f in sorted_freq: print(c, f)