""" Using Python's built-in Higher-Order Functions (HOFs): map Dan Armendariz danallan@cs.harvard.edu """ # create an arbitrary list of numbers nums = [1, 5, 10, 8, -4, 432] print "Initial:", nums def incrementor(num): """ Increment a number by 1 """ return num + 1 def doubler(num): """ Double a number """ return num * 2 # the `map` function is a HOF that applies a function to an entire list print "Add 1: ", map(incrementor, nums) print "Double: ", map(doubler, nums)