递归调用:在调用一个函数的过程中,直接或者间接又调用了函数本身,称之为递归调用。递归的必备的两阶段:一:递推 二:回溯def foo(): print('abc') foo()foo()import sysprint(sys.getrecursionlimit())sys.getrecursionlimit(200) #设置递归次数print(sys.getrecursionlimit())def age(n): if n == 1: return 18 return age(n-1) + 2print(age(5))g=[1,[2,[3,[4,[5,[6,[7]]]]]]]def foo(g): for i in g: if type(i) is list: foo(g) else: print(i)foo(g)二分法:g=[1,2,3,4,5,6,7,8,10,13,455,678,990,11111] #从小到大排列的数字列表def foo(g,numl): print(g) if len(g) == 0: print("it is not") return fdoml=len(g) // 2 if numl > g[fdoml]: foo(g[fdoml+1:],numl) elif numl < g[fdoml]: foo(g[0:fdoml],numl) else: print('find it')foo(g,678)#zip拉链函数g='wordwrod'h=[1,2,3,4]f=zip(g,h) print(list(f))匿名函数:lambda 没有函数调用名称,只生成一次存在于内存地址。def foo(x,y): return x+yfoo(1,2)同:print(lambda x,y:x+y)(1,2) 匿名函数的使用:#max 最大sab={'a':1223'b':12345'c':34567'd':345}def foo(k): return sab[k]print(max(sab,key=foo)) 同:print(max(sab,key=lambda k:sab[k])) #min 最小print(min(sab,key=lambda k:sab[k])) #sorted 排序,默认按照首字母排序sab={'a':1223'b':12345'c':34567'd':345}print(sorted(sab,key=lambda k:sab[k],reverae=Ture)) #reverae=Ture反转#map 映射names=['df','gh','jk']u=[]for i in names: res='%s_bb' %names u.append(res)print(u)同:g=map(lambda i:'%s_bb' %i,names)print(list(g))#reduce 合并from functcols import reduce reduce(lambda x,y:x+y ,range(1,101))reduce(lambda x,y:x+y ,range(1,101),100) #设定初始值,100为初始值#filter 过滤names=['df_bb','gh_bb','jk_bb']g=filter(lambda x:x.endswith('bb'),names)print(list(g))