Popular recipes by Andrew Clark http://code.activestate.com/recipes/users/4179419/2011-09-26T23:38:24-07:00ActiveState Code RecipesCreate a nested dictionary from os.walk (Python)
2011-09-26T23:38:24-07:00Andrew Clarkhttp://code.activestate.com/recipes/users/4179419/http://code.activestate.com/recipes/577879-create-a-nested-dictionary-from-oswalk/
<p style="color: grey">
Python
recipe 577879
by <a href="/recipes/users/4179419/">Andrew Clark</a>
(<a href="/recipes/tags/dictionary/">dictionary</a>, <a href="/recipes/tags/os_walk/">os_walk</a>).
Revision 2.
</p>
<p>Creates a nested dictionary that represents a folder structure. Here is an example of what the resulting dictionary might look like:</p>
<pre class="prettyprint"><code>{
"root": {
"folder2": {
"item2": None,
"item1": None
},
"folder1": {
"subfolder1": {
"item2": None,
"item1": None
},
"subfolder2": {
"item3": None
}
}
}
}
</code></pre>