Create a list of lists from dictionary in Python

I have a dictionary as follows : d = {'a':['d'],'b':['d','e'],'c':['e','f'],'d':[],'e':['f'],'f':[]} where the keys represent each node and the values of each key represent their children. I need an output as follows: [['a','b','c'],['d','e'],['f']] - A list of lists, where the list1 has in-degree 0(level-0 nodes) and list2 has level-1 nodes, list3 has level-2 nodes and so on..

Could any of you please help me with the Python code for the same?



Read more here: https://stackoverflow.com/questions/66999199/create-a-list-of-lists-from-dictionary-in-python

Content Attribution

This content was originally published by Worthy at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: