Skip to content

collection

mlte/measurement/utility/collection.py

Utilities related to measurement collection.

flatten(*collections)

Flatten a variadic number of collections.

Parameters:

Name Type Description Default
collections Union[Any, Iterable[Any]]

The collections to flatten

()

Returns:

Type Description
List[Any]

The flattened collection

Source code in mlte/measurement/utility/collection.py
10
11
12
13
14
15
16
17
18
19
20
21
22
def flatten(*collections: Union[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