在Python中使用索引迭代列表 [英] Iterate a list with indexes in Python
本文介绍了在Python中使用索引迭代列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以发誓我已经看过接受列表的函数(或方法),例如[3, 7, 19]
并将其放入可重复的元组列表中,例如:[(0,3), (1,7), (2,19)]
使用它代替:
I could swear I've seen the function (or method) that takes a list, like this [3, 7, 19]
and makes it into iterable list of tuples, like so: [(0,3), (1,7), (2,19)]
to use it instead of:
for i in range(len(name_of_list)):
name_of_list[i] = something
但是我不记得这个名字了,谷歌搜索迭代列表"一无所获.
but I can't remember the name and googling "iterate list" gets nothing.
推荐答案
>>> a = [3,4,5,6]
>>> for i, val in enumerate(a):
... print i, val
...
0 3
1 4
2 5
3 6
>>>
这篇关于在Python中使用索引迭代列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文