out = collections.defaultdict(list)
for k, v in list(d.items()):
    n, val = re.findall('^line\\((\\d+)\\)\\.(\\w+)$', k)[0]
out[int(n)].append((val, v))
my_list = [dict(out[v]) for v in sorted(out)]
Converting flat Python Dictionary to List of Dictionaries