Created
February 16, 2017 11:35
-
-
Save zefirka/478d18e671a75ccd916fe70bc576ca08 to your computer and use it in GitHub Desktop.
Python reduce implementation
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 my_reduce(fn, lst, initial=None): | |
start = 0 | |
if not initial: | |
result = lst[0] | |
start = 1 | |
else: | |
result = initial | |
while start < len(lst): | |
result = fn(result, lst[start]) | |
start += 1 | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment