Skip to content

Instantly share code, notes, and snippets.

@drio
Created December 11, 2014 15:04
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 drio/a38b2ebb1871ec0bfcd0 to your computer and use it in GitHub Desktop.
Save drio/a38b2ebb1871ec0bfcd0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# vim: set ts=4 sw=4 et foldmethod=indent paste:
#
# ---
people = [{'name': 'Mary', 'height': 160},
{'name': 'Isla', 'height': 80},
{'name': 'Sam'}]
hs = map(lambda o: o['height'], filter(lambda o: 'height' in o, people))
sum_h = reduce(lambda a, o: a + o, hs, 0)
if sum_h > 0:
print str(sum_h/len(hs))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment