You should look into the module typing.
It has a ABC for Iterators.
An Iterator is iterable, but not all iterables are iterators...
A iterator just knows the state during iteration.
It has a ABC for Iterators.
An Iterator is iterable, but not all iterables are iterators...
from typing import Iterator x = list(it) if isinstance(it, Iterator) else [it]If you want to check if the object is in iterator, you can use the built in
iter
function:def gen(): yield 42 a = gen() b = gen() c = [1] d = [2] iter(a) is iter(a) # True, it's the same iterator iter(a) is iter(b) # False, we have two different Iterators iter(c) is iter(c) # False, two different Iterators. A list object is not an Iterator, but it's iterable. iter(c) is iter(d) # False, two different lists and two different IteratorsThe objects c and d are lists (sequences) and not Iterators. They are iterable.
A iterator just knows the state during iteration.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!