Skip to content

Instantly share code, notes, and snippets.

@leopard627
Created February 4, 2020 15:50
Show Gist options
  • Save leopard627/d81db783df0796257721c6ed01b8b54b to your computer and use it in GitHub Desktop.
Save leopard627/d81db783df0796257721c6ed01b8b54b to your computer and use it in GitHub Desktop.
your_reducer.py
def youreducer(func, seq):
tally = seq[0]
for next in seq[1:]:
tally = func(tally, next)
return tally
def add(x, y):
return x + y
youreducer((lambda x, y: x + y), [1, 2, 3, 4, 5])
>> 15
youreducer(add, [1, 2, 3, 4, 5])
>> 15
youreducer((lambda x, y: x * y), [1, 2, 3, 4, 5])
>> 120
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment