Skip to content

Instantly share code, notes, and snippets.

@maryrosecook
Created December 9, 2014 19:10
Show Gist options
  • Save maryrosecook/3c175c5cf3d2914285e9 to your computer and use it in GitHub Desktop.
Save maryrosecook/3c175c5cf3d2914285e9 to your computer and use it in GitHub Desktop.
people = [{'name': 'Mary', 'height': 160},
{'name': 'Isla', 'height': 80},
{'name': 'Sam'}]
"""
height_total = 0
height_count = 0
for person in people:
if 'height' in person:
height_total += person['height']
height_count += 1
if height_count > 0:
average_height = height_total / height_count # => 120
"""
# Rewrite the code above using map, reduce and filter
# Expected answer: 120
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment