Is there a standard name for this tree structure?

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sun Apr 4 08:10:02 EDT 2010


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...



-- 
Steven



More information about the Python-list mailing list