def translate(sent):
trans={\"merry\":\"god\", \"christmas\":\"jul\", \"and\":\"och\", \"happy\":\"gott\", \"new\":\"nytt\", \"year\":\"år\"}
word_list = sent.sp
You need to assign the replaced result back to sent
, after the for loop exhausted, then return the sent
:
def translate(sent):
trans={"merry":"god", "christmas":"jul", "and":"och", "happy":"gott", "new":"nytt", "year":"år"}
word_list = sent.split(' ')
for word in word_list:
for i,j in trans.items():
if j == word:
sent = sent.replace(word, i)
return sent
translate('xmas greeting: god jul och gott nytt år')
# 'xmas greeting: merry christmas and happy new year'