1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
from functools import reduce
res = filter(lambda x:x>1,[0,1,2])
print(type(res))
res = map(lambda x:x>1,[0,1,2])
print(type(res),list(res))
res = reduce(lambda x,y:x+y,[0,1,2])
print(res)
frunts = ['apple','banana','orange'] result = filter(lambda x:'e'in x,frunts) print(list(result)) print(frunts) print('--------') def filter_func(item): if 'e' in item: return True filter_result = filter(filter_func,frunts) print(list(filter_result))
map_result = map(filter_func,frunts) print(list(map_result))
reduce_result = reduce( lambda x,y: x*y, [1,2,3,4]) print((reduce_result))
reduce_result_str = reduce(lambda x,y:x+y,frunts) print(reduce_result_str)
|