5.3 Python中的列表配对和枚举
2014-02-13 00:07
204 查看
zip可以将两个列表配对:
enumerate编号配对操作:
[智能交易网] http://www.ea900.com
>>> x = [1, 2, 3] >>> y = [4, 5, 6] >>> zipped = zip(x, y) >>> zipped [(1, 4), (2, 5), (3, 6)] >>> x2, y2 = zip(*zipped) >>> x == list(x2) and y == list(y2) True
enumerate编号配对操作:
>>> seasons = ['Spring', 'Summer', 'Fall', 'Winter'] >>> list(enumerate(seasons)) [(0, 'Spring'), (1, 'Summer'), (2, 'Fall'), (3, 'Winter')] >>> list(enumerate(seasons, start=1)) [(1, 'Spring'), (2, 'Summer'), (3, 'Fall'), (4, 'Winter')]
[智能交易网] http://www.ea900.com
相关文章推荐
- 5.3 Python 列表
- Python遍历列表
- Python数据处理2.0.1(列表转字典)
- python 中list(列表),tupe(元组),str(字符串),dict(字典)之间的相互转换
- python 数字、字符串、列表
- Python 中 list 与 tuple (列表与元组)
- Python 列表去重
- 对python中两种列表元素去重函数性能的比较方法
- Python 列表count()函数元素次数统计
- python基础知识之改变列表的基本操作
- python中list列表的高级函数
- Python中列表元素转为数字的方法分析
- python 使用set对列表去重,并保持列表原来顺序
- Python 第二章 列表和元组(3) 列表
- Python 列表学习笔录
- python中列表、元组、字典内部功能介绍
- python 中字典嵌套列表的方法
- 第七节:python列表、元组、字典、集合
- Python学习---列表(list)
- JIRA python篇之展示多人未完成任务列表