enumerate 及python 遍历
来源:互联网 发布:js的innerhtml 编辑:程序博客网 时间:2024/06/10 01:55
Python遍历
其他语言中,比如C#,我们通常遍历数组是的方法是:
for (int i = 0; i < list.Length; i++)
{
//todo with list[i]
}
在Python中,我们习惯这样遍历:
for item in sequence:
process(item)
这样遍历取不到item的序号i,所有就有了下面的遍历方法:
for index in range(len(sequence)):
process(sequence[index])
其实,如果你了解内置的enumerate函数,还可以这样写:
for index, item in enumerate(sequence):
process(index, item)
详细出处参考:http://www.jb51.net/article/15715.htm
e.g.
s='hello world'
for index, item in enumerate(s):
print "index '%d' =" % index, item
- enumerate 及python 遍历
- python中的list遍历--enumerate
- python.enumerate() 同时遍历索引+内容
- 【原创】python enumerate遍历数组
- Python enumerate函数无法顺序遍历字典
- python enumerate
- enumerate python
- python enumerate
- Python-enumerate
- Python Enumerate
- Python - enumerate
- python enumerate()
- python:enumerate
- Python enumerate
- python-enumerate()
- python: enumerate
- python enumerate
- python enumerate
- hdu 4090 GemAnd Prince
- 重写equals方法
- [20130828]A Short History of Nearly Everything[serial]
- Mysql Innodb中undo-log和MVCC多版本一致性读 的实现
- 数据结构库
- enumerate 及python 遍历
- js -- others
- Linux下安装java
- EXTJS] 下载文件错误 BADRESPONSE: illegal character
- python csv文件写入
- 如何开发Chrome扩展程序
- xx is not in the sudoers file 问题解决【转载】
- ORA-12850
- android2.3 View视图框架源码分析之一:android是如何创建一个view的?