bilingual lexicon | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

17th Apr 2020, 5:18 PM
Pavan Sirsat
Pavan Sirsat - avatar
3 Answers
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.
17th Apr 2020, 5:24 PM
Akash
Akash - avatar
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.
17th Apr 2020, 5:26 PM
Akash
Akash - avatar
0
thanks @Akash Sil
17th Apr 2020, 5:35 PM
Pavan Sirsat
Pavan Sirsat - avatar