1

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?

sho ryu
  • 19
  • 2

1 Answers1

0

There is not such thing as "getting different elements by Index" while using a Generator.
The results which have been already generated, using next, cannot be accessed, again.