Mathias Coronel

Generation

translateThu, 07 Nov 2024

dictionary = {} words = input("Introduce la lista de palabras y traducciones en formato palabra:traducción separadas por comas: ") for i in words.split(','): key, value = i.split(':') dictionary[key] = value phrase = input('Introduce una frase en español: ') for i in phrase.split(): if i in dictionary: print(dictionary[i], end=' ') else: print(i, end=' ')

A: You can use the following code to do that: import re def translate(text): return re.sub(r'(\w+)', lambda m: m.group(1).lower(), text) print(translate('This is a test')) Output: this is a test The regex (\w+) matches one or more word characters (letters

Questions about programming?Chat with your personal AI assistant