Python - Unflatten dict
<p>I have this multi-dimensional dict:</p>

<pre><code>a = {'a' : 'b', 'c' : {'d' : 'e'}}
</code></pre>

<p>And written simple function to flatten that dict:</p>

<pre><code>def __flatten(self, dictionary, level = []):
    tmp_dict = {}
    for key, val in dictionary.items():
        if type(val) == dict:
            tmp_dict.update(self.__flatten(val, level + [key]))
        else:
            tmp_dict['.'.join(level + [key])] = val
    return tmp_dict
</code></pre>

<p>After call this function with dict <code>a</code> i get in result:</p>

<pre><code>{'a' : 'b', 'c.d' : 'e'}
</code></pre>

<p>Now, after making few instructions on this flattened dict i need to build new, multi-dimensional dict from that flattened. Example:</p>

<pre><code>&gt;&gt; unflatten({'a' : 0, 'c.d' : 1))
{'a' : 0, 'c' : {'d' : 1}}
</code></pre>

<p>The only problem I have is that i do not have a function <code>unflatten</code> :)<br>
Can anyone help with this? I have no idea how to do it.</p>

<p><strong>EDIT:</strong></p>

<p>Another example:</p>

<pre><code>{'a' : 'b', 'c.d.e.f.g.h.i.j.k.l.m.n.o.p.r.s.t.u.w' : 'z'}
</code></pre>

<p>Should be after unflatten:</p>

<pre><code>{'a': 'b', 'c': {'d': {'e': {'f': {'g': {'h': {'i': {'j': {'k': {'l': {'m': {'n': {'o': {'p': {'r': {'s': {'t': {'u': {'w': 'z'}}}}}}}}}}}}}}}}}}}
</code></pre>

<hr>

<p>And another:</p>

<pre><code>{'a' : 'b', 'c.d' : 'z', 'c.e' : 1}
</code></pre>

<p>To:</p>

<pre><code>{'a' : 'b', 'c' : {'d' : 'z', 'e' : 1}}
</code></pre>

<p>This greatly increases the difficulty of the task, i know. Thats why i had problem with this and found no solution in hours..</p>
