python lambda:函数
from functools import reduce list1=list2=list3=["a","b","c","d"]
排列组合a,b,c.d 组合3成字母字符串结果不重复一共多少种?
方法一: def add(x,y): return [str(i)+str(j) for i in x for j in y] result=reduce(add,[list1,list2,list3]) 方法二: foo=lambda np:reduce(lambda x,y:[str(i)+str(j) for i in x for j in y],np) res=foo(np=[list1,list2,list3]) print(len(res),len(list(set(res))))
答案:64种
玩具1: oo=(lambda x,y,z:x*y*z)(3,4,6) print(oo)
玩具二: lower = lambda x,y: x if x<y else y pp=lower(1,2) print(pp)
玩具三: import sys showall = lambda x:list(map(sys.stdout.write,x)) showall(['Jerry\n','Sherry\n','Alice\n']) showall = lambda x: [sys.stdout.write(line) for line in x] showall(('I\t','Love\t','You!'))