Map,Filter 和 Reduce

Map会将一个函数映射到一个输入列表的所有元素上

map(function_to_apply, list_of_inputs)

items = [1, 2, 3, 4, 5]

squared = list (map(lambda x: x**2, items))

number_list = range(-5, 5)

less_than_zero = filter(lambda x: x < 0, number_list)

from functools import reduce

product = reduce( (lambda x, y: x * y), [1, 2, 3, 4] )

 

posted on 2017-08-09 14:40  yingchen  阅读(135)  评论(0编辑  收藏  举报

导航