'Helper function for merge.
Takes a dictionary whose values are lists and returns a dict with
the elements of each list as keys and the original keys as values.'

def __dict_invert(self, data):

    outdict = {}
    for (k, lst) in data.items():
        if isinstance(lst, str):
            lst = lst.split()
        for entry in lst:
            outdict[entry] = k
    return outdict
