FunctionRacerProblemsRace

Translate With a Glossary

BeginnerHash mapsPython, JavaScript, TypeScript, Java, C++

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Hash maps problems