Python: traverse tree adding html list (ul)
<p>I have this python code that will traverse a tree structure. I am trying to add ul and li tags to the function but I am not very succesful. I though I was able to keep the code clean without to many conditionals but now I ain't so sure anymore.</p>

<pre><code>def findNodes(nodes):

    def traverse(ns):
        for child in ns:
            traverse.level += 1
            traverse(child.Children)
            traverse.level -= 1

    traverse.level = 1
    traverse(nodes)
</code></pre>

<p>This is the base function I have for traversing my tree structure. The end result should be nested ul and li tags. If need I can post my own not working examples but they might be a little confusing. </p>

<p><b>Update: Example with parameter</b></p>

<pre><code>def findNodes(nodes):

    def traverse(ns, level):
        for child in ns:
            level += 1
            traverse(child.Children, level)
            level -= 1

    traverse(nodes, 1)
</code></pre>
