Create Nested Dictionary From Flat DictionaryHow to merge two dictionaries in a single expression?How do I sort a list of dictionaries by a value of the dictionary?What is the best way to iterate over a dictionary?How can I safely create a nested directory?How do I sort a dictionary by value?How to make a flat list out of list of listsAdd new keys to a dictionary?Check if a given key already exists in a dictionaryIterating over dictionaries using 'for' loopsHow to remove a key from a Python dictionary?
How strong someone should be in order to fly without "power steering"?
What is this Amiga 2000 mod?
Should I explain the reasons for gaslighting?
Why did the World Bank set the global poverty line at $1.90?
In Pandemic, why take the extra step of eradicating a disease after you've cured it?
Finding diameter of a circle using two chords and angle between them
Does a single fopen introduce TOCTOU vulnerability?
How to use the word seem
How to make a composition of functions prettier?
Is it advisable to add a location heads-up when a scene changes in a novel?
How many sets of dice do I need for D&D?
Parsing text written the millitext font
What is the "books received" section in journals?
Is it true that "only photographers care about noise"?
Professor Roman loves to teach unorthodox Chemistry
How to represent jealousy in a cute way?
What is this object?
Can I use 220 V outlets on a 15 ampere breaker and wire it up as 110 V?
Savage Road Signs
How much web presence should I have?
As easy as Three, Two, One... How fast can you go from Five to Four?
Is all-caps blackletter no longer taboo?
What do I need to do, tax-wise, for a sudden windfall?
Realistic, logical way for men with medieval-era weaponry to compete with much larger and physically stronger foes
Create Nested Dictionary From Flat Dictionary
How to merge two dictionaries in a single expression?How do I sort a list of dictionaries by a value of the dictionary?What is the best way to iterate over a dictionary?How can I safely create a nested directory?How do I sort a dictionary by value?How to make a flat list out of list of listsAdd new keys to a dictionary?Check if a given key already exists in a dictionaryIterating over dictionaries using 'for' loopsHow to remove a key from a Python dictionary?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have the following dictionary in which keys
are parent classes and values
are a list of child classes which inherit from them.
"Animal":
["Dog"]
,
"Dog":
["Labrador"]
,
"Vehicle":
["PetrolCar",
"DieselCar"]
,
"DieselCar":
["Hyundai"]
,
"PetrolCar":
["Hyundai",
"Ford"]
As you can see, some of the parent classes are also children of another parent class (deep inheritance), i.e. Animal -> Dog -> Labrador
How can I format this so that the output represents the levels of inheritance, something like this:
"Animal":
"Dog":
"Labrador": []
,
"Vehicle":
"PetrolCar":
"Hyundai": [],
"Ford": []
,
"DieselCar":
"Hyundai": []
I also want to be able to extend the provided dataset by adding more parents or children. For example: Adding ElectricCar
as a child of Vehicle
and Tesla
as a child of ElectricCar
. And adding Cat
as a child of Animal
, with no children of it's own.
Input:
"Animal":
["Dog",
"Cat"]
,
"Dog":
["Labrador"]
,
"Vehicle":
["PetrolCar",
"DieselCar",
"ElectricCar"]
,
"DieselCar":
["Hyundai"]
,
"PetrolCar":
["Hyundai",
"Ford"]
,
"ElectricCar":
["Tesla"]
Output:
"Animal":
"Dog":
"Labrador": []
,
"Cat": []
,
"Vehicle":
"PetrolCar":
"Hyundai": [],
"Ford": []
,
"DieselCar":
"Hyundai": []
,
"ElectricCar":
"Tesla": []
python python-2.7 dictionary nested
add a comment |
I have the following dictionary in which keys
are parent classes and values
are a list of child classes which inherit from them.
"Animal":
["Dog"]
,
"Dog":
["Labrador"]
,
"Vehicle":
["PetrolCar",
"DieselCar"]
,
"DieselCar":
["Hyundai"]
,
"PetrolCar":
["Hyundai",
"Ford"]
As you can see, some of the parent classes are also children of another parent class (deep inheritance), i.e. Animal -> Dog -> Labrador
How can I format this so that the output represents the levels of inheritance, something like this:
"Animal":
"Dog":
"Labrador": []
,
"Vehicle":
"PetrolCar":
"Hyundai": [],
"Ford": []
,
"DieselCar":
"Hyundai": []
I also want to be able to extend the provided dataset by adding more parents or children. For example: Adding ElectricCar
as a child of Vehicle
and Tesla
as a child of ElectricCar
. And adding Cat
as a child of Animal
, with no children of it's own.
Input:
"Animal":
["Dog",
"Cat"]
,
"Dog":
["Labrador"]
,
"Vehicle":
["PetrolCar",
"DieselCar",
"ElectricCar"]
,
"DieselCar":
["Hyundai"]
,
"PetrolCar":
["Hyundai",
"Ford"]
,
"ElectricCar":
["Tesla"]
Output:
"Animal":
"Dog":
"Labrador": []
,
"Cat": []
,
"Vehicle":
"PetrolCar":
"Hyundai": [],
"Ford": []
,
"DieselCar":
"Hyundai": []
,
"ElectricCar":
"Tesla": []
python python-2.7 dictionary nested
1
You could build a graph from your initial dictionary, and then DFS your way through the children, building the final dict in the way
– rafaelc
Mar 25 at 14:16
add a comment |
I have the following dictionary in which keys
are parent classes and values
are a list of child classes which inherit from them.
"Animal":
["Dog"]
,
"Dog":
["Labrador"]
,
"Vehicle":
["PetrolCar",
"DieselCar"]
,
"DieselCar":
["Hyundai"]
,
"PetrolCar":
["Hyundai",
"Ford"]
As you can see, some of the parent classes are also children of another parent class (deep inheritance), i.e. Animal -> Dog -> Labrador
How can I format this so that the output represents the levels of inheritance, something like this:
"Animal":
"Dog":
"Labrador": []
,
"Vehicle":
"PetrolCar":
"Hyundai": [],
"Ford": []
,
"DieselCar":
"Hyundai": []
I also want to be able to extend the provided dataset by adding more parents or children. For example: Adding ElectricCar
as a child of Vehicle
and Tesla
as a child of ElectricCar
. And adding Cat
as a child of Animal
, with no children of it's own.
Input:
"Animal":
["Dog",
"Cat"]
,
"Dog":
["Labrador"]
,
"Vehicle":
["PetrolCar",
"DieselCar",
"ElectricCar"]
,
"DieselCar":
["Hyundai"]
,
"PetrolCar":
["Hyundai",
"Ford"]
,
"ElectricCar":
["Tesla"]
Output:
"Animal":
"Dog":
"Labrador": []
,
"Cat": []
,
"Vehicle":
"PetrolCar":
"Hyundai": [],
"Ford": []
,
"DieselCar":
"Hyundai": []
,
"ElectricCar":
"Tesla": []
python python-2.7 dictionary nested
I have the following dictionary in which keys
are parent classes and values
are a list of child classes which inherit from them.
"Animal":
["Dog"]
,
"Dog":
["Labrador"]
,
"Vehicle":
["PetrolCar",
"DieselCar"]
,
"DieselCar":
["Hyundai"]
,
"PetrolCar":
["Hyundai",
"Ford"]
As you can see, some of the parent classes are also children of another parent class (deep inheritance), i.e. Animal -> Dog -> Labrador
How can I format this so that the output represents the levels of inheritance, something like this:
"Animal":
"Dog":
"Labrador": []
,
"Vehicle":
"PetrolCar":
"Hyundai": [],
"Ford": []
,
"DieselCar":
"Hyundai": []
I also want to be able to extend the provided dataset by adding more parents or children. For example: Adding ElectricCar
as a child of Vehicle
and Tesla
as a child of ElectricCar
. And adding Cat
as a child of Animal
, with no children of it's own.
Input:
"Animal":
["Dog",
"Cat"]
,
"Dog":
["Labrador"]
,
"Vehicle":
["PetrolCar",
"DieselCar",
"ElectricCar"]
,
"DieselCar":
["Hyundai"]
,
"PetrolCar":
["Hyundai",
"Ford"]
,
"ElectricCar":
["Tesla"]
Output:
"Animal":
"Dog":
"Labrador": []
,
"Cat": []
,
"Vehicle":
"PetrolCar":
"Hyundai": [],
"Ford": []
,
"DieselCar":
"Hyundai": []
,
"ElectricCar":
"Tesla": []
python python-2.7 dictionary nested
python python-2.7 dictionary nested
edited Mar 25 at 19:33
Gary
asked Mar 24 at 23:28
GaryGary
4910
4910
1
You could build a graph from your initial dictionary, and then DFS your way through the children, building the final dict in the way
– rafaelc
Mar 25 at 14:16
add a comment |
1
You could build a graph from your initial dictionary, and then DFS your way through the children, building the final dict in the way
– rafaelc
Mar 25 at 14:16
1
1
You could build a graph from your initial dictionary, and then DFS your way through the children, building the final dict in the way
– rafaelc
Mar 25 at 14:16
You could build a graph from your initial dictionary, and then DFS your way through the children, building the final dict in the way
– rafaelc
Mar 25 at 14:16
add a comment |
1 Answer
1
active
oldest
votes
You can use recursion to produce the nested dictionary, and then remove keys that do not have any children:
data = 'Animal': ['Dog', 'Cat'], 'Dog': ['Labrador'], 'Vehicle': ['PetrolCar', 'DieselCar', 'ElectricCar'], 'DieselCar': ['Hyundai'], 'PetrolCar': ['Hyundai', 'Ford'], 'ElectricCar': ['Tesla']
def build(key):
return i:[] if i not in data else build(i) for i in data[key]
results = i:build(i) for i in data
import json
print(json.dumps(a:b for a, b in results.items() if any(h for h in b.values()), indent=4))
Output:
"Animal":
"Dog":
"Labrador": []
,
"Cat": []
,
"Vehicle":
"PetrolCar":
"Hyundai": [],
"Ford": []
,
"DieselCar":
"Hyundai": []
,
"ElectricCar":
"Tesla": []
Thanks! Could you explain how this works a little more? It works for the example provided, but fails when I add another child ofVehicle
, so I would like to tweak your code so that it works for any provided dataset
– Gary
Mar 25 at 18:51
@Gary Can you post the data with the additional child ofVehicle
, along with your desired output? Currently, if a child value does not exist in the original data, it because an element of list, and the list is the value of the parent key. However, if a key has some values that exist in the data, and some that do not, how should that be represented?
– Ajax1234
Mar 25 at 18:59
please see edited question
– Gary
Mar 25 at 19:04
@Gary Thank you. The reason why"ElectricCar"
is not included in the final output is because"ElectricCar"
does not occur in the children of"Vehicle"
and as such, it is not accessed in the loop inbuild
. However, if you add"ElectricCar"
to the list under"Vehicle"
, then the desired output is produced. Please see my recent edit, as I have this result posted.
– Ajax1234
Mar 25 at 19:12
Yes sorry your original code was working as expected. One more query - how could I make it so that all elements of the tree have a list of children which can be empty if the child does not have any children? I'll add this to the original post.
– Gary
Mar 25 at 19:28
|
show 6 more comments
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55329577%2fcreate-nested-dictionary-from-flat-dictionary%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use recursion to produce the nested dictionary, and then remove keys that do not have any children:
data = 'Animal': ['Dog', 'Cat'], 'Dog': ['Labrador'], 'Vehicle': ['PetrolCar', 'DieselCar', 'ElectricCar'], 'DieselCar': ['Hyundai'], 'PetrolCar': ['Hyundai', 'Ford'], 'ElectricCar': ['Tesla']
def build(key):
return i:[] if i not in data else build(i) for i in data[key]
results = i:build(i) for i in data
import json
print(json.dumps(a:b for a, b in results.items() if any(h for h in b.values()), indent=4))
Output:
"Animal":
"Dog":
"Labrador": []
,
"Cat": []
,
"Vehicle":
"PetrolCar":
"Hyundai": [],
"Ford": []
,
"DieselCar":
"Hyundai": []
,
"ElectricCar":
"Tesla": []
Thanks! Could you explain how this works a little more? It works for the example provided, but fails when I add another child ofVehicle
, so I would like to tweak your code so that it works for any provided dataset
– Gary
Mar 25 at 18:51
@Gary Can you post the data with the additional child ofVehicle
, along with your desired output? Currently, if a child value does not exist in the original data, it because an element of list, and the list is the value of the parent key. However, if a key has some values that exist in the data, and some that do not, how should that be represented?
– Ajax1234
Mar 25 at 18:59
please see edited question
– Gary
Mar 25 at 19:04
@Gary Thank you. The reason why"ElectricCar"
is not included in the final output is because"ElectricCar"
does not occur in the children of"Vehicle"
and as such, it is not accessed in the loop inbuild
. However, if you add"ElectricCar"
to the list under"Vehicle"
, then the desired output is produced. Please see my recent edit, as I have this result posted.
– Ajax1234
Mar 25 at 19:12
Yes sorry your original code was working as expected. One more query - how could I make it so that all elements of the tree have a list of children which can be empty if the child does not have any children? I'll add this to the original post.
– Gary
Mar 25 at 19:28
|
show 6 more comments
You can use recursion to produce the nested dictionary, and then remove keys that do not have any children:
data = 'Animal': ['Dog', 'Cat'], 'Dog': ['Labrador'], 'Vehicle': ['PetrolCar', 'DieselCar', 'ElectricCar'], 'DieselCar': ['Hyundai'], 'PetrolCar': ['Hyundai', 'Ford'], 'ElectricCar': ['Tesla']
def build(key):
return i:[] if i not in data else build(i) for i in data[key]
results = i:build(i) for i in data
import json
print(json.dumps(a:b for a, b in results.items() if any(h for h in b.values()), indent=4))
Output:
"Animal":
"Dog":
"Labrador": []
,
"Cat": []
,
"Vehicle":
"PetrolCar":
"Hyundai": [],
"Ford": []
,
"DieselCar":
"Hyundai": []
,
"ElectricCar":
"Tesla": []
Thanks! Could you explain how this works a little more? It works for the example provided, but fails when I add another child ofVehicle
, so I would like to tweak your code so that it works for any provided dataset
– Gary
Mar 25 at 18:51
@Gary Can you post the data with the additional child ofVehicle
, along with your desired output? Currently, if a child value does not exist in the original data, it because an element of list, and the list is the value of the parent key. However, if a key has some values that exist in the data, and some that do not, how should that be represented?
– Ajax1234
Mar 25 at 18:59
please see edited question
– Gary
Mar 25 at 19:04
@Gary Thank you. The reason why"ElectricCar"
is not included in the final output is because"ElectricCar"
does not occur in the children of"Vehicle"
and as such, it is not accessed in the loop inbuild
. However, if you add"ElectricCar"
to the list under"Vehicle"
, then the desired output is produced. Please see my recent edit, as I have this result posted.
– Ajax1234
Mar 25 at 19:12
Yes sorry your original code was working as expected. One more query - how could I make it so that all elements of the tree have a list of children which can be empty if the child does not have any children? I'll add this to the original post.
– Gary
Mar 25 at 19:28
|
show 6 more comments
You can use recursion to produce the nested dictionary, and then remove keys that do not have any children:
data = 'Animal': ['Dog', 'Cat'], 'Dog': ['Labrador'], 'Vehicle': ['PetrolCar', 'DieselCar', 'ElectricCar'], 'DieselCar': ['Hyundai'], 'PetrolCar': ['Hyundai', 'Ford'], 'ElectricCar': ['Tesla']
def build(key):
return i:[] if i not in data else build(i) for i in data[key]
results = i:build(i) for i in data
import json
print(json.dumps(a:b for a, b in results.items() if any(h for h in b.values()), indent=4))
Output:
"Animal":
"Dog":
"Labrador": []
,
"Cat": []
,
"Vehicle":
"PetrolCar":
"Hyundai": [],
"Ford": []
,
"DieselCar":
"Hyundai": []
,
"ElectricCar":
"Tesla": []
You can use recursion to produce the nested dictionary, and then remove keys that do not have any children:
data = 'Animal': ['Dog', 'Cat'], 'Dog': ['Labrador'], 'Vehicle': ['PetrolCar', 'DieselCar', 'ElectricCar'], 'DieselCar': ['Hyundai'], 'PetrolCar': ['Hyundai', 'Ford'], 'ElectricCar': ['Tesla']
def build(key):
return i:[] if i not in data else build(i) for i in data[key]
results = i:build(i) for i in data
import json
print(json.dumps(a:b for a, b in results.items() if any(h for h in b.values()), indent=4))
Output:
"Animal":
"Dog":
"Labrador": []
,
"Cat": []
,
"Vehicle":
"PetrolCar":
"Hyundai": [],
"Ford": []
,
"DieselCar":
"Hyundai": []
,
"ElectricCar":
"Tesla": []
edited Mar 25 at 19:45
answered Mar 25 at 15:19
Ajax1234Ajax1234
44.9k42958
44.9k42958
Thanks! Could you explain how this works a little more? It works for the example provided, but fails when I add another child ofVehicle
, so I would like to tweak your code so that it works for any provided dataset
– Gary
Mar 25 at 18:51
@Gary Can you post the data with the additional child ofVehicle
, along with your desired output? Currently, if a child value does not exist in the original data, it because an element of list, and the list is the value of the parent key. However, if a key has some values that exist in the data, and some that do not, how should that be represented?
– Ajax1234
Mar 25 at 18:59
please see edited question
– Gary
Mar 25 at 19:04
@Gary Thank you. The reason why"ElectricCar"
is not included in the final output is because"ElectricCar"
does not occur in the children of"Vehicle"
and as such, it is not accessed in the loop inbuild
. However, if you add"ElectricCar"
to the list under"Vehicle"
, then the desired output is produced. Please see my recent edit, as I have this result posted.
– Ajax1234
Mar 25 at 19:12
Yes sorry your original code was working as expected. One more query - how could I make it so that all elements of the tree have a list of children which can be empty if the child does not have any children? I'll add this to the original post.
– Gary
Mar 25 at 19:28
|
show 6 more comments
Thanks! Could you explain how this works a little more? It works for the example provided, but fails when I add another child ofVehicle
, so I would like to tweak your code so that it works for any provided dataset
– Gary
Mar 25 at 18:51
@Gary Can you post the data with the additional child ofVehicle
, along with your desired output? Currently, if a child value does not exist in the original data, it because an element of list, and the list is the value of the parent key. However, if a key has some values that exist in the data, and some that do not, how should that be represented?
– Ajax1234
Mar 25 at 18:59
please see edited question
– Gary
Mar 25 at 19:04
@Gary Thank you. The reason why"ElectricCar"
is not included in the final output is because"ElectricCar"
does not occur in the children of"Vehicle"
and as such, it is not accessed in the loop inbuild
. However, if you add"ElectricCar"
to the list under"Vehicle"
, then the desired output is produced. Please see my recent edit, as I have this result posted.
– Ajax1234
Mar 25 at 19:12
Yes sorry your original code was working as expected. One more query - how could I make it so that all elements of the tree have a list of children which can be empty if the child does not have any children? I'll add this to the original post.
– Gary
Mar 25 at 19:28
Thanks! Could you explain how this works a little more? It works for the example provided, but fails when I add another child of
Vehicle
, so I would like to tweak your code so that it works for any provided dataset– Gary
Mar 25 at 18:51
Thanks! Could you explain how this works a little more? It works for the example provided, but fails when I add another child of
Vehicle
, so I would like to tweak your code so that it works for any provided dataset– Gary
Mar 25 at 18:51
@Gary Can you post the data with the additional child of
Vehicle
, along with your desired output? Currently, if a child value does not exist in the original data, it because an element of list, and the list is the value of the parent key. However, if a key has some values that exist in the data, and some that do not, how should that be represented?– Ajax1234
Mar 25 at 18:59
@Gary Can you post the data with the additional child of
Vehicle
, along with your desired output? Currently, if a child value does not exist in the original data, it because an element of list, and the list is the value of the parent key. However, if a key has some values that exist in the data, and some that do not, how should that be represented?– Ajax1234
Mar 25 at 18:59
please see edited question
– Gary
Mar 25 at 19:04
please see edited question
– Gary
Mar 25 at 19:04
@Gary Thank you. The reason why
"ElectricCar"
is not included in the final output is because "ElectricCar"
does not occur in the children of "Vehicle"
and as such, it is not accessed in the loop in build
. However, if you add "ElectricCar"
to the list under "Vehicle"
, then the desired output is produced. Please see my recent edit, as I have this result posted.– Ajax1234
Mar 25 at 19:12
@Gary Thank you. The reason why
"ElectricCar"
is not included in the final output is because "ElectricCar"
does not occur in the children of "Vehicle"
and as such, it is not accessed in the loop in build
. However, if you add "ElectricCar"
to the list under "Vehicle"
, then the desired output is produced. Please see my recent edit, as I have this result posted.– Ajax1234
Mar 25 at 19:12
Yes sorry your original code was working as expected. One more query - how could I make it so that all elements of the tree have a list of children which can be empty if the child does not have any children? I'll add this to the original post.
– Gary
Mar 25 at 19:28
Yes sorry your original code was working as expected. One more query - how could I make it so that all elements of the tree have a list of children which can be empty if the child does not have any children? I'll add this to the original post.
– Gary
Mar 25 at 19:28
|
show 6 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55329577%2fcreate-nested-dictionary-from-flat-dictionary%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
You could build a graph from your initial dictionary, and then DFS your way through the children, building the final dict in the way
– rafaelc
Mar 25 at 14:16