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

[ad_1]

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

[ad_2]

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