enumerate 函数用于遍历序列中的元素以及它们的下标

for  i,v in  enumerate(['tic','tac','toe']):
print i,v #0 tic
#1 tac
#2 toe for i,j in enumerate(('a','b','c')):
print i,j #0 a
#1 b
#2 c for i,j in enumerate({'a':1,'b':2}):
print i,j #0 a
#1 b

遍历字典的key和value

knights={'galahad':'the pure','robin':'the brave'}
for k,v in knights.iteritems():
print k,v #galahad the pure
#robin the brave

Python 中遍历序列中元素和下标的更多相关文章

  1. python中的enumerate函数用于遍历序列中的元素以及它们的下标

    enumerate 函数用于遍历序列中的元素以及它们的下标: >>> for i,j in enumerate(('a','b','c')): print i,j 0 a1 b2 c ...

  2. 【转载】C#中遍历DataTable中的数据行

    在C#中的Datatable数据变量的操作过程中,有时候我们需要遍历DataTable变量获取每一行的数据值,例如将DataTable变量转换为List集合的时候,我们就会遍历DataTable变量, ...

  3. 关于C#中遍历字符串中的每个字符的方法

    解决方案 C#提供了两个方法用于遍历字符串. 1.第一个方法是foreach循环,这个方法快速且容易,但是与第二个方法相比它不太灵活.其使用方法如下: string testStr = "a ...

  4. ADF中遍历VO中的行数据(Iterator)

    在ADF中VO实质上就是一个迭代器, 1.在Application Module的实现类中,直接借助VO实现类和Row的实现类 TestVOImpl organizationUser = (TestV ...

  5. Python - 如何统计序列中元素出现的频次

    1.用内置的count()方法,该方法返回子字符串在字符串中出现的次数(同样适用于列表)2.用collections模块的Counter类 示例: from collections import Co ...

  6. PowerDesigner中遍历物理模型中的所有表,检查表代码、字段代码

    '***************************************************************************** '文件:CheckCode4SqlServ ...

  7. java中遍历类中的属性、调用getter&setter方法

    public static void testReflect(Object model) throws NoSuchMethodException, IllegalAccessException, I ...

  8. java中遍历List中的map问题

    List list = new ArrayList();Map map = null; while (rs.next()) { map = new HashMap(); map.put("f ...

  9. Python - 反向遍历序列(列表、字符串、元组等)的五种方式

    1. reversed() a = [1, 2, 3, 4] for i in reversed(a): print(i) 2. range(len(a)-1, -1, -1) a = [1, 2, ...

随机推荐

  1. [转]html页面调用js文件里的函数报错onclick is not defined处理方法

    原文地址:http://blog.csdn.net/ywl570717586/article/details/53130863 今天处理html标签里的onclick功能的时候总是报错:Uncaugh ...

  2. android 中使用jwt token(json web token)--java

    http://blog.csdn.net/mingzhnglei/article/details/51119836 下面贴上自己项目中的一个小小的example import com.nimbusds ...

  3. TypeError: decoding Unicode is not supported

    在试图读取网页的时候遇到TypeError: decoding Unicode is not supported, 主要原因是返回的字符串已经是unicode类型了

  4. Java编程的逻辑 (41) - 剖析HashSet

    本系列文章经补充和完善,已修订整理成书<Java编程的逻辑>,由机械工业出版社华章分社出版,于2018年1月上市热销,读者好评如潮!各大网店和书店有售,欢迎购买,京东自营链接:http:/ ...

  5. 【转】android学习日记01--综述

    转自:http://www.cnblogs.com/aiguozhe/p/3541941.html 一.总体框架 先上一张google提供官方的Android框架图: Android系统架构由5部分组 ...

  6. 关于网页游戏断线重连的思路和demo求助

    http://bbs.9ria.com/thread-146997-1-1.html —————————————————————————————————————————————————— 1:俺有什么 ...

  7. 关于使用QTcpSocket的一些总结

    QTcpSocket类的方法connectToHost会泄露内存,即使把调用这个方法的QTcpSocket实例delete掉,内存也不会释放!反复connectToHost会导致段错误,十分危险.必须 ...

  8. Fedora归档管理器支持Rar、7Z

    最新文章:Virson's Blog 方法: 在Fedora下如何安装 RAR 压缩/解压缩程序 (RAR)? RAR格式压缩包解压 命令:yum install unrar 7z格式压缩包解压 yu ...

  9. 安装OpenSSL缺失Microsoft Visual C++ 2008 Redistributables的解决方案

    在安装OpenSSL的时候通常会提示以下错误: "The Win32 OpenSSL Installation Project setup has detected that the fol ...

  10. C语言实现Linux下删除非空目录

    #include <sys/stat.h> #include <dirent.h> #include <fcntl.h> /** * 递归删除目录(删除该目录以及该 ...