darbia.utils.iterables#

Assorted utility functions.

Module Contents#

Functions#

enumerate2(→ collections.abc.Iterable[tuple[int, T]])

Yield items from an iterable with a custom index.

chunks(→ collections.abc.Iterable[tuple[T, Ellipsis]])

Yield successive n-sized chunks from iterable.

flatten(→ collections.abc.Iterable[T])

Flattens a list of lists into a single list.

Attributes#

T

darbia.utils.iterables.T[source]#
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

https://stackoverflow.com/a/24290026/8160821

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

https://stackoverflow.com/a/312464/8160821

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

https://stackoverflow.com/a/952952