@@ -142,14 +142,16 @@ def map(fn: Callable[[float], float]) -> Callable[[Iterable[float]], Iterable[fl
142
142
A function that takes a list, applies `fn` to each element, and returns a
143
143
new list
144
144
"""
145
- # TODO: Implement for Task 0.3.
146
- raise NotImplementedError ("Need to implement for Task 0.3" )
145
+
146
+ def new_fn (ls : Iterable [float ]) -> Iterable [float ]:
147
+ return [fn (x ) for x in ls ]
148
+
149
+ return new_fn
147
150
148
151
149
152
def negList (ls : Iterable [float ]) -> Iterable [float ]:
150
153
"Use `map` and `neg` to negate each element in `ls`"
151
- # TODO: Implement for Task 0.3.
152
- raise NotImplementedError ("Need to implement for Task 0.3" )
154
+ return map (lambda x : - x )(ls )
153
155
154
156
155
157
def zipWith (
@@ -168,14 +170,16 @@ def zipWith(
168
170
applying fn(x, y) on each pair of elements.
169
171
170
172
"""
171
- # TODO: Implement for Task 0.3.
172
- raise NotImplementedError ("Need to implement for Task 0.3" )
173
+
174
+ def new_fn (ls1 : Iterable [float ], ls2 : Iterable [float ]) -> Iterable [float ]:
175
+ return [fn (ls1 [i ], ls2 [i ]) for i in range (len (ls1 ))]
176
+
177
+ return new_fn
173
178
174
179
175
180
def addLists (ls1 : Iterable [float ], ls2 : Iterable [float ]) -> Iterable [float ]:
176
181
"Add the elements of `ls1` and `ls2` using `zipWith` and `add`"
177
- # TODO: Implement for Task 0.3.
178
- raise NotImplementedError ("Need to implement for Task 0.3" )
182
+ return zipWith (add )(ls1 , ls2 )
179
183
180
184
181
185
def reduce (
0 commit comments