Light Mode
Dark Mode
most wanted letter

The code below creates the dictionary, but the sorted function doesn't seem to be doing anything. I guess I'm not sure how to get the output for the return (just returning 0 for testing)... would I see the dictionary in order if I print it as below? Thanks for the help.

def checkio(text):

letters = list(text)
cntDict = {}

for letter in letters:
    if letter.isalpha():
        letter = letter.lower()
        if letter not in cntDict:
            cntDict[letter] = 1

        else:
            cntDict[letter] += 1
    else:
        continue    

sorted(cntDict.items(), key=lambda x: x[1], reverse=True)

print(cntDict)

return 0
Created: Feb. 20, 2015, 2:21 p.m.
Updated: Feb. 20, 2015, 6:49 p.m.
0
3
User avatar
MelissaCastle