Is there a standard name for this tree structure?

Steven D'Aprano steve at
Sun Apr 4 14:10:02 CEST 2010

I have a hierarchical structure something like a directory tree or a 
nested tree structure:

+-- Ape
:   +-- Chimpanzee
:   +-- Gorilla
:   +-- Human
+-- Carnivore
:   +-- Cat
:       +-- Tiger
+-- 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...


More information about the Python-list mailing list