Created
November 27, 2013 22:27
-
-
Save anonymous/7684257 to your computer and use it in GitHub Desktop.
This file contains 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
#reduce(function, sequence) | |
print reduce(lambda x, y: x+y, range(1,11)) | |
def red(funct, seq): | |
for x in seq: #do this for every x in this list | |
return funct(seq) | |
def adding(x): | |
return sum(x) | |
print red(adding, range(1,11)) | |
# Reduce vraca jednu vrednost, tako sto redom uzima clanove liste i u ovom | |
# slucaju ih sabira , ili poziva prvi argument(funkciju) i primenjuje ga na | |
# prva dva clana liste(drugi argument), onda sa tim zbirom poziva funkciju | |
# koja se implementira sa sledecim clanom i tako do kraja liste. Na kraju | |
# vrati jedinicnu vrednost. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment