def append_to_list_in_dict(dict_of_lists, key, value):
    """
    Given the dict of key->lists `dict_of_lists`, appends the value `value` to
    the list at key `key` if this list exist. Otherwise, creates a list
    containing `value` and puts it at key `key`.
    """
    if key not in dict_of_lists:
        dict_of_lists[key] = [value]
    else:
        dict_of_lists[key].append(value)
