Created
February 4, 2020 15:50
-
-
Save leopard627/378b11530e23cda8ccffda5f7c966389 to your computer and use it in GitHub Desktop.
your_reducer.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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