1 2 3 4 5 6 7
d = {0:'tom',1:'cat',2:'apache',4:'server',5:'open'} items = sorted(d.items()) result = dict(enumerate([' '.join(b for a, b in items[:3])] + [b for a, b in items[3:]])) print(result)
1
{0: 'tom cat apache', 1: 'server', 2: 'open'}