作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我想知道是否有任何命令可以自动选择元组中的下一个项目而无需我输入它?
例如。
nul = 0
noofvalue = 5
value = ['a', 'b', 'c', 'd', 'e']
for nul < noofvalue:
file.write(value[0])
我可以在这里使用什么命令将“值”加 1,这样当文件循环时,它不使用值 [0],而是使用值 [1]?
nul = nul + 1
我用谷歌搜索了答案并进行了搜索,但我不明白他们在说什么,因为我对计算机编码非常陌生,所以请原谅我的无知。
最佳答案
我想你想要的是enumerate()
.我将添加我自己的示例,因为您的示例有点奇怪:
>>> L = ['a', 'b', 'c', 'd', 'e']
>>> for index, value in enumerate(L):
... try:
... print L[index+1] # Prints the next item in the list
... except IndexError:
... print 'End of the list!'
...
b
c
d
e
End of the list!
关于python - 选择列表中下一个元组的命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18996185/
前文链接: Spring复杂的BeanFactory继承体系该如何理解? ----上 Spring复杂的BeanFactory继承体系该如何理解? ----中 Spring IoC容器 Applica
我正在努力实现这个目标 | Div | |Div nav wrapper| | logo | |con
我正在尝试从下拉菜单中的链接进行模式启动。模态似乎启动了(网站变灰),但看不到。来自不在下拉列表中的常规链接的模式工作得很好。我愚弄了 jquery,但由于我是 jquery 的新手,所以没有任何结果
我是一名优秀的程序员,十分优秀!