def get_common_values()

in annotation/annotation/tasks/services.py [0:0]


def get_common_values(items: List[List[Any]]) -> List[Any]:
    """
    Get common values from list of lists.
    For example:
    Items:
        [
            [{"a": 1, "b": 2, "c": 3}, {"d": 4}, {"e": 5}],
            [{"d": 4}, {"f": 6}],
            [{"d": 4}, {"g": 7}],
        ]
    In result:
        [{"d": 4}]
    """
    if not items:
        return []
    common_items = copy.deepcopy(items[0])
    for nested_items in items[1:]:
        common_items = [item for item in common_items if item in nested_items]
        if not common_items:
            return []
    return common_items