[Python] How to get the item currently pointed at by iterator without incrementing?

Discussão em 'Python' iniciado por Stack, Abril 5, 2025.

  1. Stack

    Stack Membro Participativo

    Is there a way to get the item pointed at by an iterator in python without incrementing the iterator itself? For example how would I implement the following with iterators:

    looking_for = iter(when_to_change_the_mode)
    for l in listA:
    do_something(looking_for.current())
    if l == looking_for.current():
    next(looking_for)

    Continue reading...

Compartilhe esta Página