Is there a way to get a generator/iterator that yields the reverse of enumerate
:
from itertools import izip, count
enumerate(I) # -> (indx, v)
izip(I, count()) # -> (v, indx)
without pulling in itertools
?
You can do this with a simple generator expression:
((v, i) for i, v in enumerate(some_iterable))
Here as a list comprehension to easily see the output:
>>> [(v, i) for i, v in enumerate(["A", "B", "C"])]
[('A', 0), ('B', 1), ('C', 2)]
((v, indx) for indx, v in enumerate(I))
if you really want to avoid itertools
. Why would you?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With