def generate_versions()

in runtool/runtool/runtool.py [0:0]


def generate_versions(data: Iterable[dict]) -> Dict[Any, Versions]:
    """
    Converts an Iterable collection of dictionaries to a single dictionary
    where each value is a `runtool.datatypes.Versions` object.
    If two dictionaries has the same keys, their values are appended to the
    `Versions` object.

    example:

    >>> generate_versions([{"a": 1}])
    {'a': 1}

    >>> generate_versions([{"a": 1}, {"a": 2}])
    {'a': Versions([1, 2])}

    >>> generate_versions(
    ...     [
    ...         {"a":1},
    ...         {"a":2,"b":3},
    ...     ]
    ... )
    {'a': Versions([1, 2]), 'b': 3}
    """

    # creates a new Versions object for any new keys and appends
    # the value to the created Versions object
    result = defaultdict(Versions)
    for dct in data:
        for key, value in dct.items():
            result[key].append(value)
    return dict(result)