Implement Map

Map is a function which takes another function and applies it to each item in a list, returning the new list.

1
2
3
def map(the_function, the_list):
    # return a new list with the_function
    # applied to each element in the_list

Using only head and tail as defined by the List ADT, implement map.

Use your implementation of map to apply the function:

1
2
def polynomial(x):
    return 3 * x * x - 5 * x + 1

to the list \([32, 57, 16, 8, 38]\).

×

Problem Loading...

Note Loading...

Set Loading...