darbia.utils.iterables
#
Assorted utility functions.
Module Contents#
Functions#
|
Yield items from an iterable with a custom index. |
|
Yield successive n-sized chunks from iterable. |
|
Flattens a list of lists into a single list. |
Attributes#
- darbia.utils.iterables.enumerate2(iterable: collections.abc.Iterable[T], start: int = 0, step: int = 1) collections.abc.Iterable[tuple[int, T]] [source]#
Yield items from an iterable with a custom index.
- Yields:
index, item – The next item and the next number per step
Notes
- darbia.utils.iterables.chunks(iterable: collections.abc.Iterable[T], size: int) collections.abc.Iterable[tuple[T, Ellipsis]] [source]#
Yield successive n-sized chunks from iterable.
- Yields:
chunk – An n-sized chunk of the iterable
Notes
- darbia.utils.iterables.flatten(iterable: collections.abc.Iterable[collections.abc.Iterable[T]]) collections.abc.Iterable[T] [source]#
Flattens a list of lists into a single list.
- Parameters:
iterable – The nested lists to flatten.
- Returns:
The flattened iterable.
- Return type:
flattend_iterable
Examples
>>> flatten([['a'],['b']]) ['a', 'b']
Notes