Hi, I'm working on a program where a user can put any type of words and my program brings out the different types of words and the top 5 most used words this is my code:
contador = {}
grupo = {}
while True :
palabras=input("ponga palabras aqui ")
if palabras.lower() == "x":
break
for linea in palabras:
palabras = linea.split()
for palabra in palabras:
palabra = palabra.lower().strip(".,")
if palabra not in contador:
contador[palabra] = 1
else:
contador[palabra] += 1
longitud = len(palabra)
if longitud not in grupo:
grupo[longitud] = { palabra }
else:
grupo[longitud].add( palabra )
print("total de palabras distintat" , len(contador))
print('Las diez palabras más comunes son:')
for palabra in sorted( contador, key = contador.get, reverse=True )[:5]:
print('\t',palabra,':',contador[palabra],'ocurrencias')
But the problem I have is that it takes only one letter: if I put a word it only takes the last letter of the word. How can I make him take the whole word?