• messed up order

Question related to mission The Most Wanted Letter


I wanted to have my dictionary alphabetically sorted when I create it. However, it fails the 'fsbd' case, where s pushes in front of b, mixing up the order. And I am not sure why?

def checkio(text):
small_letters = map(chr, range(ord('a'), ord('z')+1))
only_characters = ""
sorted_dict = {}
counter = list()

for i in text.lower():
    if i in small_letters:
        only_characters = only_characters + only_characters.join(i)

for x in sorted(only_characters):
    sorted_dict[only_characters[only_characters.index(x)]] =  only_characters.count(x)
highest = max(counter)

return sorted_dict.keys()[sorted_dict.values().index(highest)]