def map_and_merge_dict_keys(fn, d):
    def merge_fn(*args):
        accumulated = set()
        for l in args:
            accumulated.update(l)
        return sorted(accumulated)
    output = {}
    for k, v in d.iteritems():
        if fn(k) not in output:
            output[fn(k)] = []
        output[fn(k)].append(v)
    return dict((f_k, merge_fn(*v)) for f_k, v in output.iteritems())
dataset/ETHPy150Open dnanexus/dx-toolkit/src/python/test/coveragereport.py/map_and_merge_dict_keys/original