polymerist.genutils.iteration ============================= .. py:module:: polymerist.genutils.iteration .. autoapi-nested-parse:: Tools for simplifying iteration over collections of items Attributes ---------- .. autoapisummary:: polymerist.genutils.iteration.T polymerist.genutils.iteration.T1 polymerist.genutils.iteration.T2 polymerist.genutils.iteration.V Functions --------- .. autoapisummary:: polymerist.genutils.iteration.iter_len polymerist.genutils.iteration.product polymerist.genutils.iteration.sliding_window polymerist.genutils.iteration.powerset polymerist.genutils.iteration.asiterable polymerist.genutils.iteration.modify_dict polymerist.genutils.iteration.sort_dict_by_keys polymerist.genutils.iteration.sort_dict_by_values polymerist.genutils.iteration.cartesian_grid Module Contents --------------- .. py:data:: T .. py:data:: T1 .. py:data:: T2 .. py:function:: iter_len(itera: Iterable) Get size of an iterable object where ordinary len() call is invalid (namely a generator) Note that this will "use up" a generator upon iteration .. py:function:: product(itera: Iterable[T]) -> T Multiplicative analogue to builtin sum() .. py:function:: sliding_window(items: Iterable[T], n: int = 1) -> Generator[tuple[T], None, None] Generates sliding windows of width n over an iterable collection of items E.g. : sliding_window('ABCDE', 3) --> (A, B, C), (B, C, D), (C, D, E) .. py:function:: powerset(items: Iterable[T], exclude_empty: bool = False, exclude_full: bool = False) -> Generator[tuple[T], None, None] Generate all possible subsets of a set. Can optionally exclude the empty set or the complete set (or both) .. py:function:: asiterable(arg_val: Union[T, Iterable[T]]) -> Iterable[T] Permits functions expecting iterable arguments to accept singular values .. py:data:: V .. py:function:: modify_dict(some_dict: dict[Hashable, V], modifier_fn: Callable[[Hashable, V], Any]) -> None Recursively modifies all values in a dict in-place according to some function .. py:function:: sort_dict_by_keys(targ_dict: dict, reverse: bool = False) -> dict[Any, Any] Sort a dictionary according to the values of each key .. py:function:: sort_dict_by_values(targ_dict: dict, reverse: bool = False) -> dict[Any, Any] Sort a dictionary according to the values of each key .. py:function:: cartesian_grid(param_dict: dict[str, Iterable[Any]]) -> Generator[dict[str, Any], None, None] Accepts a dict maping keys to all valid parameter values for that key Generates all possible choices of parameters as dicts with exactly one parameter value per key