-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathproblem_30.py
More file actions
26 lines (20 loc) · 956 Bytes
/
Copy pathproblem_30.py
File metadata and controls
26 lines (20 loc) · 956 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
'''
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. Use the higher order function map()
to write a function translate()that takes a list of English
words and returns a list of Swedish words.
'''
# I added some modification for if there are words not in dic
def translate(list_a):
dic = {"merry":"god", "christmas":"jul", "and":"och",\
"happy":"gott","new":"nytt", "year":"år"}
return list(map(lambda x:dic[x] if x in dic else False, list_a))
# "if dict.get(x)" - would work just fine
# map must return list of same number
# That's why the else part is needed
ab = ['merry','and','new','sad'] # 'sad' not in the dictionary
print(translate(ab))