my_utilities.iterables package¶
Submodules¶
my_utilities.iterables.chunk module¶
Module with functions for generate chunks
- my_utilities.iterables.chunk.chunks(iterable, size_chunk)[source]¶
Method for splitting into many parts with len size_chunk generator
- Parameters:
iterable (Union[List[Any], Tuple[Any, ...]]) – object to split
size_chunk (int) – size_chunk
- Returns:
generator of split iterable object len generator equal cnt variable
- Return type:
Generator
- Raises:
TypeError – if incorrect type of iterable or size_chunk variables
ValueError – if size_chunk variable is not in a valid value
my_utilities.iterables.split module¶
Module with functions for split iterable objects
- my_utilities.iterables.split._validate_type(iterable)[source]¶
Validate the type of variable iterable
- Parameters:
iterable (Union[List[Any], Tuple[Any, ...]]) – Iterable type to variable
- Returns:
if correct type variable iterable than return type
- Return type:
type | None
- Raises:
TypeError – if incorrect type iterable
- my_utilities.iterables.split.split(iterable, cnt)[source]¶
Method for splitting into equal cnt parts generator
- Parameters:
iterable (Union[List[Any], Tuple[Any, ...]]) – object to split
cnt (int) – cnt partitions
- Returns:
generator of split iterable object len generator equal cnt variable
- Return type:
Generator
- Raises:
TypeError – if incorrect type of iterable variable
- my_utilities.iterables.split.split_as_iterable(iterable, cnt)[source]¶
Method for splitting into equal parts
- Parameters:
iterable (Union[List[Any], Tuple[Any, ...]]) – object to split
cnt (int) – cnt partitions
- Returns:
iterable object with partitions
- Return type:
Union[List[Any], Tuple[Any, …]]
- Raises:
TypeError – if incorrect type of iterable variable
- my_utilities.iterables.split.split_with_overlap(data, n_parts=10, overlap=0)[source]¶
Split a sequence into several overlapping parts.
This function divides the input sequence into n_parts approximately equal chunks, with a specified number of overlapping elements between consecutive parts. The overlap ensures smooth transitions between parts, which can be useful for signal processing, data batching, or sliding window operations.
- Parameters:
data (list[Any] | tuple[Any, ...]) – The input iterable (e.g., list or tuple) to split.
n_parts (int) – The number of parts to split the data into.
overlap (int) – The number of elements each part should overlap with the next.
- Returns:
A generator yielding slices of data, each with the specified overlap.
- Return type:
Generator[list[Any], None, None]
- Raises:
ValueError – If n_parts is less than 1 or greater than the length of data.
TypeError – If data is not a list or tuple.
>>> list_ = [i for i in range(100)] >>> for i in split_with_overlap(list_, 10,3): >>> print(i) >>> # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] >>> # [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22] >>> # [17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32] >>> # [27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42] >>> # [37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52] >>> # [47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62] >>> # [57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72] >>> # [67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82] >>> # [77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92] >>> # [87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]