Created
August 5, 2012 02:43
-
-
Save sonesuke/3261226 to your computer and use it in GitHub Desktop.
how to use reduce in python
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
class A: | |
@property | |
def value(self): | |
return 1 | |
sample_list = [A(), A(), A()] | |
print reduce(lambda x, y: x + y.value, sample_list, 0) | |
print reduce(lambda x, y: x + y, map(lambda x: x.value, sample_list)) | |
print sum(map(lambda x: x.value, sample_list)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment