79507975

Date: 2025-03-14 01:24:03
Score: 1
Natty:
Report link

I think protocol would be appropriate here. You can define your protocol with the methods you need from Iterator

class MultiIterable(Protocol):
    def __next__(self) -> None:
        ...

    def __iter__(self) -> None:
        ...


def loop_twice(param: MultiIterable):
    for thing in param:
        print(thing)

    for thing in param:
        print(f"{thing} again")

https://typing.python.org/en/latest/spec/protocol.html#protocols

Reasons:
  • Probably link only (1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Geneviève Le Houx