Translate With a Glossary
glossary maps words to their replacements. Return a new list in which every word of words that is a key of glossary is replaced by its value, and every other word is kept as it is.
Each word is looked up once: the replacement itself is never looked up again. Keep the order and the length of words. The empty list gives [].
Example 1
glossary {"cat":"gato","dog":"perro"}
words ["the","cat","and","dog"]
returns ["the","gato","and","perro"]
cat and dog are in the glossary; the and and are not.
Example 2
glossary {"a":"b","b":"c"}
words ["a","b","c"]
returns ["b","c","c"]
a becomes b; the new b is not looked up again, so it does not become c.
Constraints
0 <= len(words) <= 100and0 <= len(glossary) <= 20- words and replacements are 1 to 10 lowercase letters
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.