Python中zip()函数用法举例
2015-04-17 17:42
686 查看
Python中zip()函数用法举例
定义:zip([iterable, ...])zip()是Python的一个内建函数,它接受一系列可迭代的对象作为参数,将对象中对应的元素打包成一个个tuple(元组),然后返回由这些tuples组成的list(列表)。若传入参数的长度不等,则返回list的长度和参数中长度最短的对象相同。利用*号操作符,可以将list unzip(解压),看下面的例子就明白了:
1 2 3 4 5 6 7 8 9 | >>> a = [1,2,3] >>> b = [4,5,6] >>> c = [4,5,6,7,8] >>> zipped = zip(a,b) [(1, 4), (2, 5), (3, 6)] >>> zip(a,c) [(1, 4), (2, 5), (3, 6)] >>> zip(*zipped) [(1, 2, 3), (4, 5, 6)] |
相关文章推荐
- Python中zip()函数用法举例
- [待完善]Python中zip()函数用法举例
- Python中zip()函数用法举例
- Python中zip()函数用法举例[转载]
- Python中zip()函数用法举例
- Python中zip()函数用法举例
- [转]Python中zip()函数用法举例
- Python中zip()函数用法举例
- Python中zip()函数用法举例
- python学习——zip()函数的用法
- Python中zip函数用法
- Python中zip()函数用法实例教程
- python3.x的zip函数用法
- zip()函数用法举例
- Python---高级函数map, filter, zip, enumerate等的用法
- 关于python使用threadpool中的函数单个参数和多个参数用法举例
- python中zip()函数的用法
- python中的zip函数用法
- python 中的map(),zip()函数以及表达式lambda用法
- python里面几个小函数的用法(map, zip, round)