[Python] Is there an elegant way to cycle through a list N times via iteration (like...

Discussão em 'Python' iniciado por Stack, Maio 11, 2025.

  1. Stack

    Stack Membro Participativo

    I'd like to cycle through a list repeatedly (N times) via an iterator, so as not to actually store N copies of the list in memory. Is there a built-in or elegant way to do this without writing my own generator?

    Ideally, itertools.cycle(my_list) would have a second argument to limit how many times it cycles... alas, no such luck.

    Continue reading...

Compartilhe esta Página