函数式编程
高阶函数
Python学习交流Q群:906715085####
map(func, *iterable)
def fn(x, y, z):
pass
map(fn, range(10), range(10), range(10))
Python学习交流Q群:906715085###
filter(func, iterable)
sorted(iterable, key=None, reverse=False)
sorted('AGFBDC')
sorted('ACDacbdE') # ['A', 'C', 'D', 'E', 'a', 'b', 'c', 'd']
# 按字符顺序排序,不区分大小写
def f(ch):
code = ord(ch) # 得到编码
if (97+26) >code >= 97:
code -= 32
return code
sorted('ACDacbdE', key=f) # ['A', 'a', 'b', 'C', 'c', 'D', 'd', 'E']
递归调用
闭包 closure
def fa(a, b):
c