重访 list comprehension
来源:互联网 发布:如何运行java web程序 编辑:程序博客网 时间:2024/05/22 17:47
数学的眼光
数学上,我们使用如下的表达式用于描述列表(或者集合,元组,以及向量等):
S = {x^2 : x in {0 ... 9}}V = (1, 2, 4, 8, ..., 2^12)M = {x | x in S and x even}
>>> S = [x**2 for x in range(0, 10)]>>> V = [2**i for i in range(13)]>>> M = [x for x in S if x%2==0]
效率与简洁
类list comprehension
[ … for …] ⇒ ( … for …)
>>> t = (x**2 for x in range(10))>>> t<generator object <genexpr> at 0x037EF170>
[ … for … ] ⇒ {k:v for k, v in …}
>>> t = [('InsideZhang', 24), ('LiXin', 24)] # 此时构成list的每一个元素必须长度为2 # 否则长度为其他时,t[0]无法指派>>> { k:v for k, v in t}{'InsideZhang': 24, 'LiXin': 24}
for k, v in t # 逐元素地取出,t[0], t[1] ... # t[0][0] ⇒ k # t[0][1] ⇒ v
0 0
- 重访 list comprehension
- List comprehension
- Python List Comprehension, Dictionary Comprehension
- 列表解析 list comprehension
- python list comprehension
- [python] List Comprehension
- list comprehension and nested list
- Python 进阶——重访 list
- [Haskell学习]Parallel list comprehension
- Python——List Comprehension
- 列表推导(List Comprehension)
- Python 进阶——重访 list (二)
- Python中的列表推导式(list comprehension)
- python map和list comprehension 效率比较
- Python列表推导式(List comprehension)
- python:列表推导式,list comprehension
- Python中的 list comprehension 以及 generator
- Python列表推导式(List comprehension)
- POJ 1930 Dead Fraction(gcd—枚举循环节,无限循环小数变最简分数)
- JQuery插件——通用分页组件
- 一起talk C栗子吧(第一百回:C语言实例--使用信号量进行进程间同步与互斥一)
- Android应用坐标系统全面详解
- Linux帮助命令
- 重访 list comprehension
- 欢迎使用CSDN-markdown编辑器
- ViewController的自定义转场动画
- Ant打包Apk(上)
- Qt5链接Mysql的驱动命令
- Messager通信
- ACM解题总结——关于最长回文子串
- Oracle_取随机数函数的常用方法
- HDU 2104 hide handkerchief【数论】