匿名函数 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]])
posted @ 2020-03-11 18:15  不带R的墨菲特  阅读(162)  评论(0编辑  收藏  举报