map(func,list),映射
reduce (func,list),递归
filter(func,list),过滤
三个函数的入参都是function,list。
def not_empty(s):
return s and s.strip()
filter(not_empty, ['A', '', 'B', None, 'C', ' '])
# 结果: ['A', 'B', 'C']
这里的and:
python 中的and从左到右计算表达式,若所有值均为真,则返回最后一个值,若存在假,返回第一个假值。