python3 zip()
来源:互联网 发布:google地球 类似软件 编辑:程序博客网 时间:2024/05/21 08:55
Make an iterator that aggregates elements from each of the iterables.
Returns an iterator of tuples, where the i-th tuple contains the
i-th element from each of the argument sequences or iterables. The
iterator stops when the shortest input iterable is exhausted. With a single
iterable argument, it returns an iterator of 1-tuples. With no arguments, it
returns an empty iterator. Equivalent to:
def zip(*iterables):
# zip('ABCD', 'xy') --> Ax By
sentinel = object()
iterables = [iter(it) for it in iterables]
while iterables:
result = []
for it in iterables:
elem = next(it, sentinel)
if elem is sentinel:
return
result.append(elem)
yield tuple(result)
举例:
>>> k = list(zip(*[[1,2,3],[4,5,6]]))
>>> k
[(1, 4), (2, 5), (3, 6)]
zip()是内置函数, 能把迭代对象进行聚合,返回值是迭代对象-聚合后的元组,用list()函数把它转化为列表
Returns an iterator of tuples, where the i-th tuple contains the
i-th element from each of the argument sequences or iterables. The
iterator stops when the shortest input iterable is exhausted. With a single
iterable argument, it returns an iterator of 1-tuples. With no arguments, it
returns an empty iterator. Equivalent to:
def zip(*iterables):
# zip('ABCD', 'xy') --> Ax By
sentinel = object()
iterables = [iter(it) for it in iterables]
while iterables:
result = []
for it in iterables:
elem = next(it, sentinel)
if elem is sentinel:
return
result.append(elem)
yield tuple(result)
举例:
>>> k = list(zip(*[[1,2,3],[4,5,6]]))
>>> k
[(1, 4), (2, 5), (3, 6)]
zip()是内置函数, 能把迭代对象进行聚合,返回值是迭代对象-聚合后的元组,用list()函数把它转化为列表
文档那个等价函数值得学习,那个iter()、next()用法并不简单。
>>> k = list(zip(*[[1,2,3],[4,5,6]]))
>>> k
[(1, 4), (2, 5), (3, 6)]
>>> k=zip(*[[1,2,3],[4,5,6]])
>>> k
<zip object at 0x000000000313F088>
>>> list(k)
[(1, 4), (2, 5), (3, 6)]
0 0
- python3 zip()
- python3 zip的用法
- Python3.6 zip lambda
- python3 zip函数
- python3 ZIP文件密码破解
- Python3 zip,lambda,map,reduce的使用
- python3.x的zip函数用法
- python3.5版本中的zip函数
- Python3.2 实现zip压缩与解压缩功能
- python3解决解压zip文件是文件名乱码问题
- python3使用了更多内存优化的技巧,比如,python3的zip就是生成可迭代的对象
- zip
- zip
- zip
- zip
- zip
- zip
- Zip
- 150,项目管理器git的使用
- 对STL的一些小计
- PtSetResource() 导致 Memory fault 的原因分析
- 扣丁学堂——文件管理
- 有n个整数,指定位置m处插入g个值(用指针和函数)
- python3 zip()
- 基于C/S模式的简单聊天程序(服务器篇)
- 【虚幻4】学习总结3-蓝图入门2
- 使用Maven Profile按需加载开发、测试和产品环境的配置文件
- 056_最长公共子序列
- Linux网络编程入门
- 23种设计模式(17)_行为型_中介者模式(Mediator Pattern)
- xcode7 Enable Zombie Objects 没反应...
- Makefile 使用总结