Python - Efficiently building a dictionary
<p>I am trying to build a dict(dict(dict())) out of multiple files, which are stored in different numbered directories, i.e. </p>

<pre><code>/data/server01/datafile01.dat
/data/server01/datafile02.dat
...
/data/server02/datafile01.dat
/data/server02/datafile02.dat
...
/data/server86/datafile01.dat
...
/data/server86/datafile99.dat
</code></pre>

<p>I have a couple problems at the moment:</p>

<ol>
<li>Switching between directories </li>
</ol>

<p>I know that I have 86 servers, but the number of files per server may vary. I am using:</p>

<pre><code>for i in range(1,86):
    basedir='/data/server%02d' % i
    for file in glob.glob(basedir+'*.dat'):
        Do reading and sorting here
</code></pre>

<p>but I cant seem to switch between the directories properly. It just sits in the first one and gets stuck it seems when there are no files in the directory</p>

<ol>
<li>Checking if key already exists</li>
</ol>

<p>I would like to have a function that somehow checks if a key is already present or not, and in case it isnt creates that key and certain subkeys, since one cant define dict[Key1][Subkey1][Subsubkey1]=value</p>

<p>BTW i am using Python 2.6.6 </p>
