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 geo=[ "australia", "europe",[ "spain", "germany", "belgium", ], "america",[ "california",[ "los angeles", "san francisco", "berkeley" ], "texas", "utah" ], "asia" ] print "Our geography as a flat list:\n" print geo def printlist(lst,indent=0): for item in lst: if isinstance(item,(list,tuple)): printlist(item,indent+1) else: print " -> "*indent, item print "\nOur geography as a tree:\n" printlist(geo) # 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: australia europe -> spain -> germany -> belgium america -> california -> -> los angeles -> -> san francisco -> -> berkeley -> texas -> utah asia -- "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 http://www.catb.org/~esr/halloween/halloween4.html _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor