- Engineering
- Computer Science
- do the following with python use the testing code at...
Question: do the following with python use the testing code at...
Question details
do the following with python use the testing code at bottom of page MUST PASS ALL TESTS
def sum_linked_list(lst, fn):
""" Applies a function FN to each number in LST and returns the
sum
of the resulting values
>>> square = lambda x: x * x
>>> double = lambda y: 2 * y
>>> lst1 = link(1, link(2, link(3, link(4))))
>>> sum_linked_list(lst1, square)
30
>>> lst2 = link(3, link(5, link(4, link(10))))
>>> sum_linked_list(lst2, double)
44
"""
def _test():
import doctest
doctest.testmod(verbose=True)
if __name__ == "__main__":
_test()
Solution by an expert tutor
