[Python] Single object iterator

Discussão em 'Python' iniciado por Stack, Setembro 10, 2025.

  1. Stack

    Stack Membro Participativo

    To be consistent with an API, I have to return an iterator which yields exactly one value and then stops (it must be a correct value returned by .__iter__()). So far, I have:

    return (myobject for _ in [0])


    Is there a better (more "Pythonic") way to do this?

    Continue reading...

Compartilhe esta Página