-
Notifications
You must be signed in to change notification settings - Fork 0
Week 3 04 06
fengttt edited this page Apr 6, 2020
·
3 revisions
- Queens
- Map
- Introduce class
- For the functions we implemented in previous homeworks, like zip, filter, etc, are actually used by python language (or standard library) itself, thus causing lots of confusion. You may want to rename them as myFilter, etc.
- We will continue our toy exercises. Write a function fib,
def fib(n):
''' Return the n-th Fibonaci number. f(0) == 1, f(1) == 1, f(n) = f(n-1) + f(n-2) '''
def myMap(f, a):
''' f is a function, a is a list. Return a list calling f on each of the elements of a.
For example, myMap(fib, [0, 1, 2, 3, 4]) should return [1, 1, 2, 3, 5]
'''
- You should have the myFilter function working by now. What is the
len(myFilter(myMap(fib, list(range(10000))), isEven))
Oh, those parenthesis! My eyes!
4. Queens, yes, you can do it!