Is a dictionary the right data structure for this?
<p>I would like to use a data structure that would allow me to store my data like this:</p>

<pre><code>data[1][a]
data[1][b]
data[1][c]
data[1][d]
data[2][a]
data[2][b]
</code></pre>

<p>...
With the labels a, b, c, d known from the beginning, while  i iter over the 1, 2, ... from a list.</p>

<p>I thought about using a dictionary:</p>

<pre><code>dict={} #How to initialize the dictionary ?

mylist=(1, 2, ...)
for i in mylist:
    dict[i][a]=something
    dict[i][b]=something_else
    etc
</code></pre>

<p>1) Is it the best data structure to use ? Else what would you use ?
2) If using the dictionary structure how to initialize the dictionary with the labels a, b, c &amp; d ?</p>

<p>If you want to have data[1][a] using dict. You could have a dict of dicts and initialize like so.</p>

<pre><code>dict={}

mylist=(1, 2, 3)
labels = ('a','b','c','d')
something = 'foo'

for i in mylist:
    for l in labels:
        if(i in dict):
            dict[i].update({l:something})
        else:
            dict[i] = {l:something}
</code></pre>

python dictionary data-structures label