Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def foldr(op,initial,seq):
- if not seq: #seq is empty
- return initial
- else:
- return op(seq[0], foldr(op, initial, seq[1:])) #recursion on the rest of the list
- def foldl(op, z, seq):
- if not seq:
- return z
- else:
- return foldl(op, op(z, seq[0]), seq[1:])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement