Wednesday, July 8, 2015

Python: map of sequence

def cube(x): return x*x*x

res=map(cube, range(1, 11))

print res
#! python

# reduce(func, sequence)" returns a single value constructed by
# calling the binary function func on the first two items of the sequence, 
# then on the result and the next item, and so on

def add(x,y): return x+y

r=reduce(add, range(1, 11))
print r # 55