Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def sumA(n):
- if not n:#if n is empty list
- return 0
- head, *tail = n
- return head + sumA(tail)
- #print(sumA([1,2,3,4,5]))
- print(list(map(sumA, [[1,1,1],[2,2,2],[3,3],[4,4],[5,5]])))
- print(sumA(list(map(sumA, [[1,1,1],[2,2,2],[3,3],[4,4],[5,5]]))))
- from functools import reduce
- import operator
- def product(xs):
- return reduce(operator.mul, xs, 1)
- print(product([1,2,3,4]))
- def sumB(xs):
- return reduce(operator.add, xs, 1)
- print(sumB([1,2,3,4]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement