Last active
February 4, 2020 15:50
-
-
Save leopard627/a7d5614de1583a7ecdb5363e1e2d4c68 to your computer and use it in GitHub Desktop.
learning_python_example
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