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>I suggest a list of dictionaries. And I suggest that you replace your suggested iteration:</p>

<pre><code>for i in mylist:
    dict[i][a]=something
</code></pre>

<p>With this:</p>

<pre><code>for elem in list_of_dicts:
    elem[a] = something
</code></pre>

<p>If for some reason, you really need the list index, you can do the following:</p>

<pre><code>for i, elem in enumerate(list_of_dicts):
    elem[a] = something # or list_of_dicts[i][a] = something
</code></pre>

<p>Regarding your question about initializing.</p>

<pre><code>list_of_dicts = list()
list_of_dicts.append( { a : b, c : d } )
list_of_dicts.append( { e : f, g : h } )
</code></pre>

python dictionary data-structures label