3 ms·
I think the "full" version is easier to read: T = TypeVar("T") def odd_numbers(nums: Iterable[T]) -> Iterator[T]: for n in nums: if
by nerdponx 6y ago
I think the "full" version is easier to read:
T = TypeVar("T")
def odd_numbers(nums: Iterable[T]) -> Iterator[T]:
for n in nums:
if n % 2 == 1:
yield n
Although yet another option is to just return the generator instead of immediately yielding from it:
T = TypeVar("T")
def odd_numbers(nums: Iterable[T]) -> Iterator[T]:
return (n for n in a if n % 2 == 1)