Skip to content

Instantly share code, notes, and snippets.

@maryrosecook
Created November 11, 2013 19:28
Show Gist options
  • Select an option

  • Save maryrosecook/7418874 to your computer and use it in GitHub Desktop.

Select an option

Save maryrosecook/7418874 to your computer and use it in GitHub Desktop.
FP
@lealbaugh

Copy link
Copy Markdown
names = ["alice", "bob", "cynthia"]
codenames = map(lambda x: hash(x), names)
print codenames

@maryrosecook

Copy link
Copy Markdown
Author
people = [{'name': 'Mary', 'height': 160},
          {'name': 'Isla', 'height': 80},
          {'name': 'Sam'}]

@LeslieK

LeslieK commented Nov 11, 2013

Copy link
Copy Markdown

def average_height(people):
people_with_heights = filter(lambda x: 'height' in x, people)
heights = map(lambda x: x['height'], people_with_heights)
total = reduce(lambda acc, x: acc + x, heights, 0)
return total/len(heights)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment