python zip enumerate函数
zip是一个内置函数, 接受两个或多个序列,并将他们拉到一起,成为一个元组列表。每个元组包含各个序列中的一个元素。
s = 'abc'
t = [0,1,2]
zip(s,t)
>>>[('a',0),('b',1),('c',2)]
如果需要遍历序列中的元素以及它们的下标,可以使用内置函数enumerate:
for index,elemet in enumerate('abc'):
print index,element
>>> 0 a 1 b 2 c
python zip enumerate函数的更多相关文章
- python的enumerate函数
python的enumerate函数用于循环索引和元素 例如 foo = 'abc' for i , ch in enumerate(foo): print ch, '(%d)' % i 输出结果: ...
- Python学习笔记之Python的enumerate函数
Python 的 enumerate() 函数就像是一个神秘的黑箱,你无法简单地用一句话来概括这个函数的作用与用法. enumerate() 函数属于非常有用的高级用法,而对于这一点,很多初学者甚至中 ...
- [python拾遗]enumerate()函数
在python中处理各类序列时,如果我们想显示出这个序列的元素以及它们的下标,可以使用enumerate()函数. enumerate()函数用于遍历用于遍历序列中的元素以及它们的下标,用法如下: 1 ...
- python之enumerate()函数的探究
原地址:http://www.newsmth.net/nForum/#!article/Python/95860 最近用到enumerate()函数,于是查了相关的资料. 其中的一 ...
- python中enumerate 函数
enumerate 函数用于遍历序列中的元素以及它们的下标: >>> for i,j in enumerate(('a','b','c')): print i,j 0 a 1 b ...
- python之enumerate函数:获取列表中每个元素的索引和值
源码举例: def enumerate_fn(): ''' enumerate函数:获取每个元素的索引和值 :return:打印每个元素的索引和值 ''' list = ['] for index, ...
- Python中enumerate函数用法详解
enumerate函数用于遍历序列中的元素以及它们的下标,多用于在for循环中得到计数,enumerate参数为可遍历的变量,如 字符串,列表等 一般情况下对一个列表或数组既要遍历索引又要遍历元素时, ...
- python中enumerate()函数的用法
描述: enumerate() 函数用于将一个可遍历的数据对象(如列表.元组或字符串)组合为一个索引序列,同时列出数据和数据下标,一般用在 for 循环当中.其英文意为:枚举,列举. 函数说明: 语法 ...
- python中enumerate( )函数的使用
enumerate( )函数是遍历一个序列中的元素以及元素对应的下标 seq = ['one', 'two', 'three'] for i, element in enumerate(seq): p ...
随机推荐
- Action的动态调用方法
Action执行的时候并不一定要执行execute方法,我们可以指定Action执行哪个方法: 1. 方法一(通过methed属性指定执行方法): 可以在配置文件中配置Action的时候用method ...
- Vmware虚拟机
1.在虚拟机安装完系统后找到相对应的保存路径如:D:\VMware\VOS\Win7x64OS 2.该目录下面会有很多文件和文件夹,其中配置文件Windows 7 x64.vmx和硬盘文件Window ...
- HDU-1159 Common Subsequence 最长上升子序列
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- GIT的标准文档 使用和服务介绍
http://www.kancloud.cn/kancloud/how-to-use-github/42192 1. 探索GitHub 熟悉Git的人几乎都知道并喜欢GitHub,反过来GitHub也 ...
- Longest Substring with At Most K Distinct Characters
Given a string, find the longest substring that contains only two unique characters. For example, gi ...
- 【leetcode】Subsets II
Subsets II Given a collection of integers that might contain duplicates, S, return all possible subs ...
- c++0x新特性实例(比较常用的)
//array #include <array> void Foo() { array<> a; generate(a.begin(),a.end(),rand); sort( ...
- mysql in 查询优化
2014年11月29日21:01:01 场景:有的时候查询数据库的select in 语句中会有非常多不连续的数值,会很影响查询效率 方法:将select in 查询转换成多个select betwe ...
- mysqldump备份
备份工具1.mysqldump(数据量很大时不推荐使用) myisam 锁表 innodb 行锁 mysqldump --help | less #查看mysql所有的语法 mysqldu ...
- VS2010 error C3861: “exit”: 找不到标识符
#include <stdlib.h> 可以解决问题