V
V
vanya_782020-08-14 12:07:11
Python
vanya_78, 2020-08-14 12:07:11

How to write a text translation function using a word translation dictionary?

The function definition is: def translate_text(text: str, vocabulary: dict) -> str:

The function generates and returns a new string based on the given text, in which:

  • all characters that are not included in the words remain as they are.
  • if the word is not found in the transmitted translation dictionary, then it remains in the same form.
  • all words that are found in the passed translation dictionary are replaced with their alternative meanings.

1) param text: text of type str
2) param vocabulary: a Python dictionary in which:
  • keys - a word from the text in lowercase
  • values ​​- a string with an alternative value

3) return (function result): text in which words are replaced with their alternative meanings from the passed translation dictionary.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-08-14
@bacon

Come on, test tasks, you will do it yourself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question