Generation

generate functionSat, 29 Apr 2023

Leer una cadena de caracteres e imprimir las dos palabras que más veces se repite

text = "a b c d b a c a b d a" def find_most_used_words(text): text = text.split() unique_words = list(set(text)) unique_words.sort() result = [] for word in unique_words: count = text.count(word) result.append((word, count)) result.sort(key=lambda x: x[1], reverse=True) return result[0:2] find_most_used_words(text)

Want to kickstart your project?Use the new AI Studio to create your code