Getting element of current python itertools loop

I know that you can use c = cycle(['a', 'b', 'c']) to cycle through the elements using c.next() , but is it possible to get the current element of the iterator?

for example, if c.next() returns 'c' , it means the iterator has been to 'b' before. Is there a way to get 'b' without using next() ?

+5
source share
1 answer

Iterators / generators have no way to get the current value. You must either save a link to it, or create some kind of shell that holds onto it for you.

+2
source

All Articles