list module

toolbox.list.chunk_list(lst: List[T], size: int) List[List[T]]

Split a list into chunks of a specified size.

Args:

lst (List[T]): The list to chunk. size (int): Size of each chunk.

Returns:

List[List[T]]: List of chunks.

toolbox.list.compact(lst: List[Any]) List[Any]

Remove None, empty strings, and False values from a list.

Args:

lst (List[Any]): The list to compact.

Returns:

List[Any]: List with falsy values removed.

toolbox.list.dedupe(lst: List[T], key: Callable[[T], Any] = None) List[T]

Remove duplicates from a list based on a key function.

Args:

lst (List[T]): The list to deduplicate. key (Callable[[T], Any], optional): Function to extract comparison key. Defaults to None (use item itself).

Returns:

List[T]: List with duplicates removed, order preserved.

toolbox.list.flatten_list(lst: List[Any]) List[Any]

Recursively flatten a list of arbitrarily nested lists.

Args:

lst (List[Any]): The nested list.

Returns:

List[Any]: A single flattened list.

toolbox.list.group_by(lst: List[T], key: Callable[[T], Any]) Dict[Any, List[T]]

Group list items by a key function.

Args:

lst (List[T]): The list to group. key (Callable[[T], Any]): Function that returns the grouping key.

Returns:

Dict[Any, List[T]]: Dictionary mapping keys to lists of items.

toolbox.list.interleave(*lists: List[T]) List[T]

Interleave multiple lists element by element.

Args:

*lists: Variable number of lists to interleave.

Returns:

List[T]: Interleaved list.

toolbox.list.partition(lst: List[T], predicate: Callable[[T], bool]) tuple[List[T], List[T]]

Partition a list into two lists based on a predicate.

Args:

lst (List[T]): The list to partition. predicate (Callable[[T], bool]): Function that returns True or False.

Returns:

tuple[List[T], List[T]]: Tuple of (matching, non-matching) items.

toolbox.list.unique(lst: List[T]) List[T]

Return unique elements from a list while preserving order.

Args:

lst (List[T]): The input list.

Returns:

List[T]: List with duplicates removed, order preserved.