Skip to content

Instantly share code, notes, and snippets.

@zefirka
Created February 16, 2017 11:35
Show Gist options
  • Save zefirka/478d18e671a75ccd916fe70bc576ca08 to your computer and use it in GitHub Desktop.
Save zefirka/478d18e671a75ccd916fe70bc576ca08 to your computer and use it in GitHub Desktop.
Python reduce implementation
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