def invert_dict(dictionary, multi_value=False):
    """
    Returns a new dictionary keyed by the values in <dictionary> and
    containing the matching key.
    
    If <multi_value> is True, values are sets of keys that matched each
    value in the iterables contained in <dictionary>.
    
    I realize that this is a poor explanation but I'm in a hurry here . . .
    """
    flipped_dict = {}
    if multi_value:
        for k, v in dictionary.items():
            for item in v:
                if item in flipped_dict:
                    flipped_dict[item].add(k)
                else:
                    flipped_dict[item] = set([k])
    else:
        for k, v in dictionary.items():
            flipped_dict[v] = k
    return flipped_dict
