Last active
December 20, 2015 05:29
-
-
Save sgentile/6079044 to your computer and use it in GitHub Desktop.
simple python map and reduce
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 Person: | |
def __init__(self, name, age): | |
self.name = name | |
self.age = age | |
people = [] | |
people.append(Person("Steve", 43)) | |
people.append(Person("Tyler", 8)) | |
print map(lambda x: x.age, people) # [43,8] | |
print reduce(lambda x, y: x+y.age, people, 0) # 51 | |
print filter(lambda x: x.age > 10, people) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment