def create_dict_lookup(driver_names, key):
    """
    Creates a dict lookup from the list of Models.

    :param driver_names: List[leapp.models.Model[K, V]]
    :param key: a key value, that will be used as a primary key to generate a
        result Dict
    :return: Dict[leapp.models.Model[K,V].key, leapp.models.Model[K,V]]
    :raises ValueError: if there are duplicates of leapp.models.Model[K,V].key
    :raises AttributeError: if key not in K (Model attributes)

    Example:
    >>> create_dict_lookup([Model(a=1, b=2), Model(a=2, b=3)], key="b") == {
    >>>     2: Model(a=1, b=2),
    >>>     3: Model(a=2, b=3),
    >>> }
    """
    lookup = {getattr(item, key): item for item in driver_names}
    if len(lookup) != len(driver_names):
        raise ValueError("A duplicated key(s) found")
    return lookup