Created
December 9, 2014 19:10
-
-
Save maryrosecook/3c175c5cf3d2914285e9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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