def invert_dict(d):
    """Return a dictionary whose keys are the values of d, and whose
    values are lists of the corresponding keys of d
    """
    inverse = dict()
    for key in d:
        val = d[key]
        inverse.setdefault(val,[]).append(key)
    return inverse