Functional Programming - map()
From the docs:
map(function,sequence)calls function(item)for each of the sequenceβs items and returns a list of the return values. For example, to compute some cubes:
>>> def cube(x): ... return x*x*x ... >>> map(cube,range(1,11)) [1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]
More than one sequence may be passed; the function must then have as many arguments as there are sequences and is called with the corresponding item from each sequence (or Noneif some sequence is shorter than another). For example:
>>> seq=range(8) >>> def add(x,y): return x+y ... >>> map(add,seq,seq) [0, 2, 4, 6, 8, 10, 12, 14]
If I wanted the sum of squares of 1 to 10, then this would do it:
>>> def square(x): ... return x*x ... >>> sum(map(square,range(1,11))) 385













