polymerist.genutils.iteration
Tools for simplifying iteration over collections of items
Attributes
Functions
|
Get size of an iterable object where ordinary len() call is invalid (namely a generator) |
|
Multiplicative analogue to builtin sum() |
|
Generates sliding windows of width n over an iterable collection of items |
|
Generate all possible subsets of a set. Can optionally exclude the empty set or the complete set (or both) |
|
Permits functions expecting iterable arguments to accept singular values |
|
Recursively modifies all values in a dict in-place according to some function |
|
Sort a dictionary according to the values of each key |
|
Sort a dictionary according to the values of each key |
|
Accepts a dict maping keys to all valid parameter values for that key |
Module Contents
- polymerist.genutils.iteration.T
- polymerist.genutils.iteration.T1
- polymerist.genutils.iteration.T2
- polymerist.genutils.iteration.iter_len(itera: Iterable)[source]
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
- polymerist.genutils.iteration.product(itera: Iterable[T]) T[source]
Multiplicative analogue to builtin sum()
- polymerist.genutils.iteration.sliding_window(items: Iterable[T], n: int = 1) Generator[tuple[T], None, None][source]
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)
- polymerist.genutils.iteration.powerset(items: Iterable[T], exclude_empty: bool = False, exclude_full: bool = False) Generator[tuple[T], None, None][source]
Generate all possible subsets of a set. Can optionally exclude the empty set or the complete set (or both)
- polymerist.genutils.iteration.asiterable(arg_val: T | Iterable[T]) Iterable[T][source]
Permits functions expecting iterable arguments to accept singular values
- polymerist.genutils.iteration.V
- polymerist.genutils.iteration.modify_dict(some_dict: dict[Hashable, V], modifier_fn: Callable[[Hashable, V], Any]) None[source]
Recursively modifies all values in a dict in-place according to some function
- polymerist.genutils.iteration.sort_dict_by_keys(targ_dict: dict, reverse: bool = False) dict[Any, Any][source]
Sort a dictionary according to the values of each key