pyiter.combination
1from typing import Iterable, Iterator, Tuple 2from itertools import combinations 3from .transform import Transform, T 4 5 6class CombinationTransform(Transform[T, Tuple[T, ...]]): 7 """ 8 A transform that yields all possible combinations of n elements from the input iterable. 9 """ 10 11 def __init__(self, iter: Iterable[T], n: int): 12 super().__init__(iter) 13 self.n = n 14 15 def __do_iter__(self) -> Iterator[Tuple[T, ...]]: 16 yield from combinations(self.iter, self.n)
7class CombinationTransform(Transform[T, Tuple[T, ...]]): 8 """ 9 A transform that yields all possible combinations of n elements from the input iterable. 10 """ 11 12 def __init__(self, iter: Iterable[T], n: int): 13 super().__init__(iter) 14 self.n = n 15 16 def __do_iter__(self) -> Iterator[Tuple[T, ...]]: 17 yield from combinations(self.iter, self.n)
A transform that yields all possible combinations of n elements from the input iterable.