def extend_list_in_dict(dict_of_lists, key, values):
    """
    Given the dict of key->lists `dict_of_lists`, extends the list at key `key`
    with the values `values` if this list exist. Otherwise, puts the list
    `values` at key `key`.
    """
    if key not in dict_of_lists:
        dict_of_lists[key] = values
    else:
        dict_of_lists[key].extend(values)
