Skip to content

collection

Utilities related to measurement collection.

flatten(*collections)

Flatten a variadic number of collections.

Parameters:

Name Type Description Default
collections Any | Iterable[Any]

The collections to flatten

()

Returns:

Type Description
list[Any]

The flattened collection

Source code in mlte/measurement/utility/collection.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
def flatten(*collections: Any | Iterable[Any]) -> list[Any]:
    """
    Flatten a variadic number of collections.

    :param collections: The collections to flatten

    :return: The flattened collection
    """
    clone = [collection for collection in collections]
    for i, _ in enumerate(clone):
        while i < len(clone) and isinstance(clone[i], (list, tuple)):
            clone[i : i + 1] = clone[i]  # noqa
    return clone