Replace the word in the list with the value from the dictionary

I have a list of words

words = ['apple', 'peach', 'tomato']

And a dictionary

translations = {'apple':' apfel', 'banana': 'banane', 'peach': 'pfirsich', 'orange': 'apfelsine'}

I need to find all the words that match the keys in the dictionary and replace the missing ones with something like <none> and put it all into a new list. That is, the result should be as follows:

result = ['apfel', 'pfirsich', '<none>']

The list and the dictionary can have more than 10,000 items if it is important.


try this:

words = ['apple','peach','tomato']
translations = {'apple':'apfel','banana':'banane','peach':'pfirsich','orange':'apfelsine'}
result = [translations.get(i, '<none>') for i in words]
#['apfel', 'pfirsich', '<none>']