I create a simple generator using
x = (i for i in range(100))
If I want to find the 50th element I would use next(itertools.islice(x, 50, None))
to get it, but then I want to find the 25th in [1..100], if I continue to use next(itertools.islice(x, 25, None))
, I will get 76 instead of 25.
How can I get different elements by index in a generator?