Python: tree structure and numerical codes?
<p>I'm using Python and I have some data that I want to put into a tree format and assign codes to. Here's some example data:</p>

<pre><code>Africa    North Africa    Algeria
Africa    North Africa    Morocco
Africa    West Africa     Ghana
Africa    West Africa     Sierra Leone
</code></pre>

<p>What would be an appropriate tree structure for this data?</p>

<p>Also, is there a way that I can then retrieve numerical codes from this tree structure, so that I could query the data and get codes like the following example?</p>

<pre><code>def get_code(place_name):
    # Python magic query to my tree structure
    return code
get_code("Africa") # returns 1
get_code("North Africa") # returns 1.1
get_code("Morocco") # returns 1.1.2
</code></pre>

<p>Thank you for your help - I still have much to learn about Python :)</p>
