def double(n): return 2*n def pluralize(st): return st+'s' #def mapDouble(nums): # return map(double, nums) def mapPluralize(strings): return map(pluralize, strings) def myMap(f, elts): result = [] for e in elts: result.append(f(e)) return result def square(n): return n*n def mapSquare(nums): return map(square, nums) def upper(st): return st.upper() def mapUpper(strings): return map(upper, strings) def mapDouble(nums): # Locally define the double function within mapDouble. # This may only be used inside mapDouble and not outside def double(n): return 2*n return map(double,nums) def mapScale(factor,nums): # Can't define this outside of mapScale, because # it needs to refer to parameter named "factor" def scale(n): return factor*n return map(scale, nums) def mapPrefixes(string): # Can't define this outside of mapPrefixes, because # it needs to refer to parameter named "string" def prefix(i): return string[:i+1] return map(prefix, range(len(string))) def mapPreConcat(pre, strings): def concat(i): return pre+strings[i] return map(concat, range(len(strings)))