【发布时间】:2012-07-13 14:45:23
【问题描述】:
循环遍历python列表以获取内容和它们的索引是很常见的。我通常做的事情如下:
S = [1,30,20,30,2] # My list
for s, i in zip(S, range(len(S))):
# Do stuff with the content s and the index i
我觉得这个语法有点难看,尤其是zip 函数内部的部分。有没有更优雅/Pythonic 的方式来做到这一点?
【问题讨论】: