Python基础-常用的内置函数

内置函数filter
str = ['a', 'b', 'c', 'd']
def fansik(num):
    if num != "a":
        return num

ret = filter(fansik, str)
print(ret)
print(list(ret))
内置函数map
str = ['a', 'd', 'b']
def fansik(num):
    return num + "fansik"
ret = map(fansik, str)
print(ret)
print(list(ret))
内置函数reduce
from functools import reduce
def add1(x, y):
    return x + y
print(reduce(add1, range(1, 101)))
内置函数lambda
from functools import reduce
print(reduce(lambda x, y: x + y, range(1, 101)))

 

posted @ 2017-10-16 11:34  fansik  阅读(165)  评论(0编辑  收藏  举报