当前位置: 代码迷 >> 综合 >> python map, reduce, filter 函数
  详细解决方案

python map, reduce, filter 函数

热度:12   发布时间:2023-12-07 21:38:38.0
(lambda x: x)("hi")(lambda :2**3)()(lambda x: x % 10)(123)
 
 
map 函数
 
 
map(lambda x: x + x, "abcde")map(lambda x, y: x + y, range(0, 8), range(0, 8))map(None, range(3), range(10, 13))b = map(lambda x: x ** 2, range(4))
print ba = [0, 6, 12, 18]
print map(lambda x, y: (x * y), a, b)def f1():l = []map(lambda x: l.append(x), xrange(1, 11))return l
print f1()

reduce 函数
r = reduce(lambda x, y: x + y, range(101))
reduce(lambda x, y: x + y, range(1, 100, 20))print r
filter函数
def f(x):return x % 2 != 0 and x % 3 != 0print filter(f, range(2, 10))a = filter(lambda x: x % 2 == 0, range(0, 20, 3))
print adef f2(x):return x != 'a'filter(f2, "writaline")


  相关解决方案