map-filter-reduce
听说函数式编程很⑥,咱也不知道,咱也不晓得,还没实际用过。emmm。。。。,先mark下Python中和函数式编程有关的部分功能先,又开始水了,立个flag🚩:慢慢完善 map 先看下Python官方文档的说法 map(function, iterable, …),返回一个将 function 应用于 iterable 中每一项并输出其结果的迭代器。 如果传入了额外的 iterable 参数,function 必须接受相同个数的实参并被应用于从所有可迭代对象中并行获取的项。 见识一下 123456789101112>>> def cook(something):... if something == "cow":... return "hamburger"... elif something == "tomato":... return "chips"... elif something == "chicken":... return "ddrumstick"... elif something == "corn":... return "popcorn"...>>> list(map(cook, ["cow", "tomato", "chicken", "corn"]))['hamburger', 'chips', 'ddrumstick', 'popcorn']