When I'm iterating over an iterator object is there a way to know what index i'm at by calling some function on the object?
Asked
Active
Viewed 56 times
0
-
can you share some of your code? if you mean using a for loop you can just print out the iterator if its a integer – yampelo May 26 '14 at 13:10
-
This is not a duplicate! The original question asks how to access indices along with the iterator, and this question asks how to obtain them from the (given) iterator object itself. Please be more careful when closing questions as duplicates. – user4815162342 May 26 '14 at 13:17
-
Since the question is closed, here is the answer in comment form: In Python, iterator is merely an *interface*, and an iterator only needs to provide the `next` method to satisfy it. An iterator object could, in theory, provide functionality other than the `next()` method, but most of them don't. Out of the built-in iterator types, such as the list iterator, dict iterators, etc., none support querying the current index. – user4815162342 May 26 '14 at 13:18