day16 匿名函数
2024-09-06 19:44:30
# 匿名函数
# 函数名 = lambda 参数1,(参数2,....) : 返回值 [注意:匿名函数不允许换行]
# 匿名函数返回值和正常函数一样可以是任意数据类型
# def add(x,y):
# return x+y
# add = lambda x, y: x+y
# print(add(3,6)) # dic = {'k1':10,'k2':100,'k3':30}
# def func(num):
# return dic[num] # 返回值是dic里面的value值
# print(max(dic,key=lambda k:dic[k])) # ret = filter(lambda y:y>6, [6,5,4,-9,88,67])
# for i in ret:
# print(i) # ret = map(lambda x: x ** 2 ,[-1,2,3,-4])
# for i in ret:
# print(i) # min max map filter sorted 都可以和 key= 合作 # 练习题:使用匿名函数把(('a'),('b')),(('c'),('d'))变成列表[{'a':'c'},{'b':'d'}]
# max min sorted filter map
# 匿名函数 === 内置函数
# zip res1 = zip((('a'),('b')),(('c'),('d')))
res2 = map(lambda tup:{tup[0]:tup[1]},res1)
print(list(res2))
最新文章
- 解密jQuery事件核心 - 绑定设计(一)
- 夺命雷公狗----Git---7---GitHub当仓库本地使用(完)
- SQL(触发器)
- jquery fadeOut 异步
- spring mvc 中文乱码 post与get的方法解决
- iOS开发—字典转模型,KVC设计模式
- ubuntu系统软件
- Android下的Linux指令集
- cf D. Levko and Array
- LINUX小技巧,如何在指定目录下搜索到含特定关键字的文件。
- Laravel默认使用utf8_unicode_ci 即使数据库是utf8_general_ci
- Graphical Analysis of German Parliament Voting Pattern
- julia 安装
- ERP结账不自动清台的解决办法
- PHP7语法知识(三):时间与日期、表单、类与对象、正则表达式、错误异常处理、图像处理
- MySQL登录报错ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
- github的pull request是指什么意思
- Grape教程-params
- Solr 后台查询实例 (工作备查)
- 【转】腾讯移动品质中心TMQ [腾讯 TMQ] 测试管理平台大比拼