import collections
MY_FUN_STR = filter(str.isalpha, (str.lower("ThE_SLATe-Maker")))
frequencies = collections.Counter(MY_FUN_STR)
a = sorted(frequencies, reverse=True)
for letter in frequencies:
print ('{} appears {}'.format(letter, frequencies[letter]) + " times")
The output now is:
t appears 2 times
h appears 1 times
e appears 3 times
s appears 1 times
l appears 1 times
a appears 2 times
m appears 1 times
k appears 1 times
r appears 1 times
There are two issues with your code:
forloop.keyparameter tosorted(), so that the function knows to sort based on frequency.Here is a code snippet that resolves both of these issues:
This prints the following: