Is there a way to get a generator / iterator that returns the return value of enumerate :
enumerate
from itertools import izip, count enumerate(I) # -> (indx, v) izip(I, count()) # -> (v, indx)
without pulling itertools ?
itertools
((v, indx) for indx, v in enumerate(I))
if you really want to avoid itertools . Why do you need?
You can do this with a simple expression:
((v, i) for i, v in enumerate(some_iterable))
Here is a list to easily see the result:
>>> [(v, i) for i, v in enumerate(["A", "B", "C"])] [('A', 0), ('B', 1), ('C', 2)]
I am not sure if I understood your question correctly. But here is my solution. Code Based: https://docs.python.org/2/library/functions.html#enumerate
def enumerate_rev(sequence, start=0): n = start for elem in sequence: yield elem,n n += 1