Provide for the worst; the best can take care of itself
Yiddish proverb
What does this function do? Simple: it takes an input string (word or sentence or number, it doesn't matter: the input function returns always a string type) and creates a dictionary where as keys we have the characters of the input, and as values the number of repetitions of that character. If for example we give this input from keyboard 'A simple test regarding the input function and the dictionary object', output will be:
Write word or sentence: A simple test regarding the input function and the dictionary object
{'A': 1, ' ': 10, 's': 2, 'i': 6, 'm': 1, 'p': 2, 'l': 1, 'e': 6, 't': 8, 'r': 3, 'g': 2, 'a': 3, 'd': 3, 'n': 6, 'h': 2, 'u': 2, 'f': 1, 'c': 3, 'o': 3, 'y': 1, 'b': 1, 'j': 1}
new_couples = [(value, key) for (key, value) in mydict.items()]
Where mydict is our dictonary object and mydict.items() returns the view object of the couples of the list, creating an iterable object. Now the last step: call the sorted function where the argument is new_couples list. The sorted() method sorts the element of a given iterable in a specific order. Without specifying any further, this method sorts the argument in the ascending order of its own first element. Instead we will sort in descending order through setting parameter reverse = True . So, let's put all pieces togheter:
Output:
Write word or sentence: A simple test regarding the input function and the dictionary object
  --> 10
t --> 8
n --> 6
i --> 6
e --> 6
r --> 3
o --> 3
d --> 3
c --> 3
a --> 3
u --> 2
s --> 2
p --> 2
h --> 2
g --> 2
y --> 1
m --> 1
l --> 1
j --> 1
f --> 1
b --> 1
A --> 1