In general, there&#39;s 2 solutions to your &quot;unflattening&quot; problem.  <br><br>A) The general solution: Keep track of the depth you&#39;re at, and add tabs/spaces (&#39;\t&#39; * depth) as necessary.<br clear="all">
<br>B) The xml solution: Use (for example) the dom.minidom module, and create a new &quot;ul node&quot; and populate it with children, at each level.  Then, have the xml do the printing for you.<br><br>&lt;nitpick&gt;<br>
For what it&#39;s worth, I may have a slight nit-pick of your final output.  I don&#39;t believe you can technically have a &lt;ul&gt; child of a &lt;ul&gt; node.  I&#39;m not absolutely sure on that, but my quick google searching has appeared to confirm.  If that turns out to be true, you&#39;ll need to change the structure of your output.<br>
<br>&lt;ul&gt;<br>    &lt;li&gt;<br>        1,0,data<br>        &lt;ul&gt;<br>            &lt;li&gt;555,1,image&lt;/li&gt;<br>            ...<br>        &lt;/ul&gt;<br>    &lt;/li&gt;<br>&lt;/ul&gt;<br><br>All of that is, of course, null and void if you define your own xml scheme.  <br>
<br>&lt;/nitpick&gt;<br><br><br>--<br><br>I enjoy haiku<br>but sometimes they don&#39;t make sense;<br>refrigerator?<br>
<br><br><div class="gmail_quote">On Fri, Jun 4, 2010 at 11:15 AM,  <span dir="ltr">&lt;<a href="mailto:jjcrump@uw.edu">jjcrump@uw.edu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
All,<br>
<br>
any observations might be helpful. For the display of database contents I have the following problem:<br>
<br>
Database querys will return data to me in tuples of the following sort:<br>
each tuple has a unique id, a parent id, and a type.<br>
<br>
a parent id of 0 indicates that the element has no parent.<br>
not all data elements have children<br>
image elements have no children and must have a parent<br>
<br>
So the contents of the db is a tree of sorts:<br>
<br>
(1, 0, work)<br>
(555, 1, image)<br>
(556, 1, work)<br>
(557, 556, image)<br>
(558, 556, work)<br>
(559, 558, image)<br>
(560, 558, work)<br>
(561, 556, image)<br>
(562, 556, image)<br>
(563, 1, work)<br>
(564, 563, work)<br>
(565, 1, work)<br>
<br>
I have a function that will traverse this tree, summoning lists of tuples at each leaf. Well and good; it took a lot of trial and error, but it was a fine education in tree traversal.<br>
<br>
def makeHeirarchy(id):<br>
    id = parentPath(id)[-1]<br>
    rootimages = getImages(id[0])<br>
    rootworks = getWorks(id[0])<br>
    heirarchy = treeTraversal(rootworks, [id, rootimages])<br>
    return heirarchy<br>
<br>
## which calls this recursive function:<br>
<br>
def treeTraversal(listIn,result):<br>
    for x in listIn:<br>
        if not getWorks(x[0]):<br>
            result.append(x)<br>
            result.append(getImages(x[0]))<br>
        else:<br>
            result.append(x)<br>
            result.append(getImages(x[0]))<br>
            treeTraversal(getWorks(x[0]), result)<br>
    return result<br>
<br>
My problem is that this returns the tuples to me in a flat list.<br>
I&#39;ve been trying to work out how I can get it to return some sort of nested structure: nested lists, dictionaries, or html thus:<br>
<br>
&lt;ul&gt;<br>
&lt;li&gt;1,0,data&lt;/li&gt;<br>
    &lt;ul&gt;<br>
    &lt;li&gt;555, 1, image&lt;/li&gt;<br>
    &lt;li&gt;556, 1, data&lt;li&gt;<br>
        &lt;ul&gt;<br>
        &lt;li&gt;557, 556, image&lt;/li&gt;<br>
        &lt;li&gt;561, 556, image&lt;/li&gt;<br>
        &lt;li&gt;562, 556, image&lt;/li&gt;<br>
        &lt;li&gt;558, 556, data&lt;/li&gt;<br>
            &lt;ul&gt;<br>
            &lt;li&gt;559, 558, image&lt;/li&gt;<br>
            &lt;li&gt;560, 558, image&lt;/li&gt;<br>
            &lt;/ul&gt;<br>
        &lt;/ul&gt;<br>
    &lt;li&gt;563, 1, data&lt;/li&gt;<br>
        &lt;ul&gt;<br>
            &lt;li&gt;564, 563, data&lt;/li&gt;<br>
        &lt;/ul&gt;<br>
    &lt;li&gt;565, 1, data&lt;/li&gt;<br>
    &lt;/ul&gt;<br>
&lt;/ul&gt;<br>
<br>
_______________________________________________<br>
Tutor maillist  -  <a href="mailto:Tutor@python.org" target="_blank">Tutor@python.org</a><br>
To unsubscribe or change subscription options:<br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
</blockquote></div><br>