[Solved] Collapsing dict keys into one key: Python [closed]


Since the keys aren’t necessarily consecutive, the best way I can think of would be this:

items = sorted(d.items())

dict(enumerate([' '.join(b for a, b in items[:3])] + [b for a, b in items[3:]]))

Here’s a demo.

9

solved Collapsing dict keys into one key: Python [closed]