def lists2dict(keys, vals):
    """Creates a dictionary from `keys` and `vals`, creating lists for each key,
    and appending values to those lists. This is useful if you have many values
    per key and need to convert to a dict."""
    ret = {}
    for k, v in zip(keys, vals):
        ret.setdefault(k, []).append(v)
    return ret