Python loop with int iterator
本问题已经有最佳答案,请猛点这里访问。
Possible Duplicate:
How to get list index and element simultaneously in Python?
我似乎记得有一种内在的方法可以做到这一点:
1 2 3 4 | i = 0 for value in values: # ...Stuff i += 1 |
但是用更简洁的语法;比如
1 2 | for value, i in fn(values): # ...Stuff |
我的记忆是正确的吗?如果是,怎么做?
1 | for i, value in enumerate(values): |