博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python 中遍历序列中元素和下标
阅读量:7185 次
发布时间:2019-06-29

本文共 431 字,大约阅读时间需要 1 分钟。

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

for  i,v in  enumerate(['tic','tac','toe']):    print  i,v    #0 tic#1 tac#2 toefor i,j in enumerate(('a','b','c')):    print i,j    #0 a#1 b#2 cfor 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

 

转载于:https://www.cnblogs.com/zwgblog/p/7170166.html

你可能感兴趣的文章
Spring JDBCTemplate使用JNDI数据源
查看>>
AssemblyInfo.cs文件的作用
查看>>
[Bug]IE11下,forms认证,出现无法保存cookie的问题
查看>>
.net学习之Attribute特性和EF关键知识点
查看>>
IIS7错误:“Web服务器被配置为不列出此目录的内容”的解决办法
查看>>
中企ITIL需软落地
查看>>
petshop4.0 具体解释之中的一个(系统架构设计)
查看>>
Html辅助方法 之 Form表单标签
查看>>
Android的SoundPool
查看>>
SharePoint 关于拓扑错误的解决方案
查看>>
HDU-3533-Escape(BFS)
查看>>
uva----(100)The 3n + 1 problem
查看>>
WF4.0(2)----设计工作流
查看>>
检查服务是否正在运行,如果未运行则启动
查看>>
SRM 624 D2L3: GameOfSegments, 博弈论,Sprague–Grundy theorem,Nimber
查看>>
演示基于SDL2.0+FFmpeg的播放器
查看>>
Markdown语法备忘
查看>>
mysql中Table is read only错误解决方法
查看>>
博客园是不是应该取消反对按钮或者改进反对按钮
查看>>
Cocos2d-X中实现批处理精灵
查看>>