0
bilingual lexicon
. Represent a small bilingual lexicon as a Python dictionary in the following fashion {"merry":"god", "christmas":"jul", "and":"och", "happy":gott", "new":"nytt", "year":"år"} and use it to translate your Christmas cards from English into Swedish. That is, write a function translate() that takes a list of English words and returns a list of Swedish words. code: def trans(lst): dicti = {"merry":"god", "christmas":"jul", "and":"och", "happy":"gott", "new":"nytt", "year":"år"} for i in lst: a = i b = dicti[a] print(b) lst1 = ['Merry', 'christmas', 'and', 'happy', 'new', 'year'] trans(lst1) why my code doesnt work
3 Antworten
0
While running this code a key error occurred because in your dictionary the m in merry is small but in your list the m in merry is capital.
Since Python is case sensitive it considers both of them as different.
I would suggest try using the lower() function.
0
Pavan Sirsat also the next time try to write and save the code in solo learn and share link, it makes executing and debugging the code easier.
0
thanks @Akash Sil