Best way to define multidimensional dictionaries in python?
<p>I'm currently using the method below to define a multidimensional dictionary in python. Question is... is this the preferred way of defining multidim dicts?</p>

<pre><code>from collections import defaultdict
def site_struct(): return defaultdict(board_struct)
def board_struct(): return defaultdict(user_struct)
def user_struct(): return dict(pageviews=0,username='',comments=0)
userdict = defaultdict(site_struct)
</code></pre>

<p>to get the following structure</p>

<pre><code>userdict['site1']['board1']['username'] = 'tommy'
</code></pre>

<p>I'm also using this to incement counters on the fly for a user without having to check if a key exists or is set to 0 already. E.g.:</p>

<pre><code>userdict['site1']['board1']['username']['pageviews'] += 1
</code></pre>
