Skip to content
Advertisement

How do I convert dict of dicts/nested dicts into dict of list

Heres the original dict

JavaScript

What I am trying to get

JavaScript

The keys in original dict represent uid.

This is my what I have done:

JavaScript

But I am rather looking for a generalized approach, to achieve without manually declaring the keys again, just so it should work with new keys in the original data.

Advertisement

Answer

Generalized (based on original version by Andrej Kesely):

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement