The questioner didn't make it clear which step to start the conversion from. If you work towards this goal from the beginning of the list, then this problem is actually not difficult.
from itertools import groupby
from functools import reduce
dic_a = {1: 7, 2: 7, 3: 9, 4: 8, 5: 8, 6: 8}
dica = dict([reduce(lambda v, e: (int(str(v[0])+str(e[0])), k), g) for k, g in
groupby(dic_a.items(), lambda v: v[1])])
>>> dica
>>> {3: 9, 12: 7, 456: 8}
Is it okay to look at it this way?
The questioner didn't make it clear which step to start the conversion from. If you work towards this goal from the beginning of the list, then this problem is actually not difficult.
python3
setdefault