Is there a standard name for this tree structure?

Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Wed Apr 7 00:18:47 EDT 2010


On Tue, 06 Apr 2010 19:16:05 +0200, egbert wrote:

> On Sun, Apr 04, 2010 at 12:10:02PM +0000, Steven D'Aprano wrote:
>  
>> I can implement this tree using a flat dict:
>> 
>> root = object()
>> data = {root: ['Mammal', 'Reptile'],
> 
> What is the advantage, or thougth behind, using an instance of object as
> the root of your flat tree ? egbert

It's a known sentinel that can't possibly clash with an entry in the tree 
except by deliberate action on the part of the caller.

I could have used None, or "root", or "this is a magic value that 
probably won't clash with an entry in the tree", or -1 as a sentinel 
instead, but they all risk accidental clashes with tree entries.



-- 
Steven



More information about the Python-list mailing list