在看filter和map 内置函数
filter函数会将经过函数过滤后的结果返回
map函数会将计算结果返回
1 from functools import reduce 2 3 l = [2, 3, 4, 5, 6, 7, 8, 9, 10] 4 s = ['ss', '你好', 'hello'] 5 6 7 def test(x): return x % 2 == 0 8 9 10 data = filter(test, l) # filter是将满足条件的结果进行返回 11 data2 = map(test, l) # map 会将计算表达式,并将结果返回,导致返回的列表为true和false 12 print(list(data)) 13 print(list(data2)) 14 输出: 15 [2, 4, 6, 8, 10] 16 [True, False, True, False, True, False, True, False, True]
reduce函数主要是进行叠加的