[Tutor] Tree Ctrl Data Structure - Help, please!

Michiel Overtoom motoom at xs4all.nl
Wed Jul 16 01:28:18 CEST 2008

Lauren wrote...

> Based on some research I've done,  I think I want my data structure to
> be a series of lists within lists:
> [...]
> Can someone give me some pointers on how to think about this
> clearly??  I'm obviously missing some steps!! :-(

I find your example a bit hard to follow.  From the node names I can't
determine a logical hierarchy; it might be the formatting of the email message.
Could you express the way you get your query results in terms of the below
geography names?  Then maybe I can think up a way how to combine those lists
into a tree.

# start of example

# this example uses a hierarchy of three levels: 1) continent, 2)
country/state, and 3) city
            "los angeles",
            "san francisco",

print "Our geography as a flat list:\n"
print geo

def printlist(lst,indent=0):
    for item in lst:
        if isinstance(item,(list,tuple)):
            print "  -> "*indent, item

print "\nOur geography as a tree:\n"

# end of example

This prints:

Our geography as a flat list:

['australia', 'europe', ['spain', 'germany', 'belgium'], 'america',
['california', ['los angeles', 'san francisco', 'berkeley'], 'texas',
'utah'], 'asia']

Our geography as a tree:

  ->  spain
  ->  germany
  ->  belgium
  ->  california
  ->   ->  los angeles
  ->   ->  san francisco
  ->   ->  berkeley
  ->  texas
  ->  utah

"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Vallopillil

More information about the Tutor mailing list