2
My teacher gave a problem to be solved by the class.
Given a sentence, we want to know which letter appears the most, always working with lowercase letter, that is, disregarding the distinction between uppercase and lowercase letters.
I coded the following solution, in python:
def letra_q_mais_aparece(frase):
alfabeto = {"a":0, "b":0, "c":0, "d":0, 'e':0, 'f':0, 'g':0, 'h':0, 'i':0, 'j':0, 'k':0, 'l':0, 'm':0, 'n':0, 'o':0,'p':0,'q':0,'r':0,'s':0,'t':0,'u':0,'v':0,'w':0,'x':0,'y':0,'z':0}
new_frase = frase.lower()
count = 0
mais_repete = ''
for letra in new_frase:
if letra in alfabeto:
alfabeto[letra] += 1
for letra in alfabeto:
if alfabeto.keys() > count:
count += letra.keys()
mais_repete += letra
return mais_repete
a = input()
print(letra_q_mais_aparece(a))
The problem happens in the second. I wanted to compare each dictionary key with the counter variable, to then locate the most repeating letter, but gives an error that says that:
if alphabet.Keys() > Count: Typeerror: '>' not supported between instances of 'dict_keys' and 'int'
How can I make this code work?
Yes, it’s for teaching purposes, but thanks for the tip!
– Diovana Valim