S
Steven D'Aprano
I have a hierarchical structure something like a directory tree or a
nested tree structure:
Mammal
+-- Ape
: +-- Chimpanzee
: +-- Gorilla
: +-- Human
+-- Carnivore
: +-- Cat
: +-- Tiger
Reptile
+-- Lizard
+-- Snake
+-- Cobra
+-- Python
This is a forest because each top-level element (Mammal, Reptile) is
itself a tree. By adding a root to the (former) top-level elements, I
turn it into a single tree.
I can implement this tree using a flat dict:
root = object()
data = {root: ['Mammal', 'Reptile'],
'Mammal': ['Ape', 'Carnivore'],
'Ape': ['Chimpanzee', 'Gorilla', 'Human'],
'Reptile': ['Lizard', 'Snake'],
# fill in the rest yourself...
}
Is there a particular name for this structure? I've been calling it a
dict-based flattened tree, but I can't shake the feeling that there is
another name for it...
nested tree structure:
Mammal
+-- Ape
: +-- Chimpanzee
: +-- Gorilla
: +-- Human
+-- Carnivore
: +-- Cat
: +-- Tiger
Reptile
+-- Lizard
+-- Snake
+-- Cobra
+-- Python
This is a forest because each top-level element (Mammal, Reptile) is
itself a tree. By adding a root to the (former) top-level elements, I
turn it into a single tree.
I can implement this tree using a flat dict:
root = object()
data = {root: ['Mammal', 'Reptile'],
'Mammal': ['Ape', 'Carnivore'],
'Ape': ['Chimpanzee', 'Gorilla', 'Human'],
'Reptile': ['Lizard', 'Snake'],
# fill in the rest yourself...
}
Is there a particular name for this structure? I've been calling it a
dict-based flattened tree, but I can't shake the feeling that there is
another name for it...