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=' ')
You can use the following code to get the desired output. import re import sys def main(): with open(sys.argv[1]) as f: for line in f: if re.search(r'(^|\s)@(\w+)', line): print(line.strip()) if __name__ == '__main__': main() The output will be