匿名函数 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]])
原文地址:https://www.cnblogs.com/SunshineKimi/p/12464290.html