forked from hcientist/OnlinePythonTutor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.txt
More file actions
15 lines (12 loc) · 398 Bytes
/
map.txt
File metadata and controls
15 lines (12 loc) · 398 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Functional programming with map
# Adapted from MIT 6.01 course notes (Section A.2.3)
# http://mit.edu/6.01/mercurial/spring10/www/handouts/readings.pdf
def map(func, lst):
if lst == []:
return []
else:
return [func(lst[0])] + map(func, lst[1:])
def halveElements(lst):
return map(lambda x: x / 2.0, lst)
input = [2, 4, 6, 8, 10]
output = halveElements(input)