天天看点

匿名函数 python

先来个开胃菜:

a=1
b=3
# 方法一
foo = lambda a,b:max(a,b)
r1= foo(a,b)
#方法2
foo1= lambda a,b: a if a>b else b
r2=foo1(1,3)
print(r1,r2)


进阶:
def  foo(it):
  return it[0]

foo3 =list(map(lambda x: x[0],[[1,3],[2,4]])      

继续阅读