map/reduce
>>> def prod(aa):
def mult(x, y):
return int(x) * int(y)
return reduce(mult, aa)
>>> prod([2, '12', 3, 4, 3])
864
>>> def norm(aa):
return aa[0].upper() + aa[1:].lower()
>>> map(norm, ['Jie', 'seiI', 'ddf'])
['Jie', 'Seii', 'Ddf']
filter
>>> def is_sus(s):
if s == 1 or s == 2:
return 1
for i in range(2,s):
if s%i == 0:
return 1
return 0
>>> filter(is_sus, range(1,101))