'how to convert a python dictionary with nested lists as values to a list of list

I want to convert a dictionary to a python list. Each values have a nested lists of lists. What I want to do is to "flatten those lists" and make the dictionary keys as the first item of each lists. As an example:

nested = {'firstKey':[[1,'x', 'aaa'],[2, 'y', 'bbb']], 'secondKey':[[3,'z', 'ccc'],[4, 'v', 'ddd']]}

The result I wanted would be:

unnested = [['firstKey',1,'x', 'aaa'],['firstKey',2, 'y', 'bbb'], ['secondKey', 3,'z', 'ccc'], ['secondKey', 4, 'v', 'ddd']]

Also I prefer not to import libraries like pandas.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source