Python标准库:内置函数zip(*iterables)
2015-06-19 11:32
197 查看
本函数是实现从多个序列生一个元组列表迭代子返回,即是从每个序列里获取一项,然后把所有的项生成元组,再把这些元组生成列表返回。如果有多个序列,以最短的序列为元组的个数。如果在参数前面添加*表示反向处理,即是从元组列表转换为分离的列表返回。
例子:
结果输出如下:
[(1, 4), (2, 5), (3, 6)]
[(1, 4), (2, 5)]
[(1, 4, 7), (2, 5, 8)]
[(1, 2), (4, 5), (7, 8)]
蔡军生 QQ:9073204 深圳
例子:
#zip() l = [1, 2, 3] x = [4, 5, 6] print(list(zip(l, x))) x = [4, 5] print(list(zip(l, x))) y = (7, 8, 9) print(list(zip(l, x, y))) lxy = list(zip(l, x, y)) print(list(zip(*lxy)))
结果输出如下:
[(1, 4), (2, 5), (3, 6)]
[(1, 4), (2, 5)]
[(1, 4, 7), (2, 5, 8)]
[(1, 2), (4, 5), (7, 8)]
蔡军生 QQ:9073204 深圳
相关文章推荐
- Python标准库:内置函数zip(*iterables)
- 《Writing Idiomatic Python》前两部分的中文翻译
- python logging
- python的smtplib发邮件
- Python OpenOPC的学习观感
- Python模块 Socket
- Python学习笔记(9):range()与xrange()函数
- Python version 2.7 required, which was not found in the registry
- Python学习笔记(8):input()与raw_input()
- python学习之小小爬虫
- 用Cython编译写出更快的Python代码
- python学习笔记之小小购物车
- Python学习 之 数据类型(邹琪鲜 milo)
- Python写的一个简单监控系统
- 使用py2exe将python 脚本生成exe可执行文件
- python网络爬虫
- Python 学习笔记10
- Python 删除特定时间段的文件
- 【练习题】有 3 个回文数字,第一个是两位数,第二个是三位数。将这两个数字相加得到第三个数字,这是个四位数。请问第三个数字是多少?
- python XML