Skip to content

Instantly share code, notes, and snippets.

@sgentile
Last active December 20, 2015 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgentile/6079044 to your computer and use it in GitHub Desktop.
Save sgentile/6079044 to your computer and use it in GitHub Desktop.
simple python map and reduce
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