Skip to content

Instantly share code, notes, and snippets.

@sonesuke
Created August 5, 2012 02:43
Show Gist options
  • Save sonesuke/3261226 to your computer and use it in GitHub Desktop.
Save sonesuke/3261226 to your computer and use it in GitHub Desktop.
how to use reduce in python
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