• It works... but not here

Question related to mission The Most Wanted Letter

 
def the_most_wanted_letter(string):
    string = "".join(sorted(string.replace(" ", "").replace("!","").lower()))
    string = {x: string.count(x) for x in set(string)}
    for element in string:
        if string.get(element) == max(string.values()):
            return element

It should work, but it doesn't

UPDATE

NOW everything works fine

def the_most_wanted_letter(string):
    string = [c.lower() for c in string if c.isalpha()]
    string = {x: string.count(x) for x in sorted(string)}
    for element in string:
        if string.get(element) == max(string.values()):
            return element

P.S Not the best way to solve this task, but wanted to finish it off.