好像没有函数式编程的课 第四部分
来源:4-5 面向对象三大特性演示
Chocolatepistol
2020-02-19
写回答
2回答
-
赵佳子彧
2021-12-09
函数式编程涉及的知识点主要就是Lambda,filter和reduce
(1)用函数实现过滤掉集合list1 = ['', 'hello', None, 'python']中的空格和空值
>>>list1 = ['', 'hello', None, 'python'] >>> list(filter(lambda s: s and s.strip(), list1)) ['hello', 'python']
(2)用函数方法实现计算集合list1 = [1, 2, 3, 4, 5]中,所有元素的和。
reduce() 函数通常用来对一个集合做一些累积操作,其基本语法格式为:reduce(function, iterable)
>>> from functools import reduce >>> list1 = [1, 2, 3, 4, 5] >>> reduce(lambda re,x:re+x, list1) 15
10 -
大周
2020-02-21
函数式编程涉及的知识点主要就是Lambda,map和reduce,看一下就能掌握了。 这个是固定的。
00
相似问题