Leer una cadena de caracteres e imprimir las dos palabras que más veces se repite
def str_to_array(str): return str.split(" ") def count_words(str): words = {} for word in str_to_array(str): if word in words: words[word] += 1 else: words[word] = 1 return words def get_two_max_words(words): max_words = [] count = 0 for word in words: if count == 0: max_words.append(word) count += 1 elif count == 1: if words[max_words[0]] <= words[word]: max_words[count-1] = max_words[count-2] max_words[count-2] = word else: max_words.append(word) count += 1 else: if words[max_words[1]] >= words[word]: continue elif words[max_words[0]] <= words[word]: max_words