Advertisement
morty0505

Untitled

Nov 25th, 2016
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.32 KB | None | 0 0
  1.  
  2.  
  3. def foldr(op,initial,seq):
  4. if not seq: #seq is empty
  5. return initial
  6. else:
  7. return op(seq[0], foldr(op, initial, seq[1:])) #recursion on the rest of the list
  8.  
  9. def foldl(op, z, seq):
  10. if not seq:
  11. return z
  12. else:
  13. return foldl(op, op(z, seq[0]), seq[1:])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement