title: How to create a 3 dimensional dictionary from 3 lists in Python
body: <p>I have 3 lists</p>
  
  <pre><code>i = ['a','b','c']
  j = ['1','2','3']
  l = ['01','02']
  </code></pre>
  
  <p>I want to create a dictionary looking something like this:</p>
  
  <pre><code>D = {'a':{'1':{'01':10, '02':100}, {'2':{'01':20,'02':50}}}
  </code></pre>
  
  <p>I want to be able to loop over <code>i, j</code> and <code>l</code> and do <code>D[i][j][l]</code> to get the value associated with it.</p>
  
  <pre><code>Ds = {}
  l_ = 0
  for i_ in range(len(i)):
      j_ = 0
      for j_ in range(len(j)):
          l_ = 0
          for l_ in range(len(l)): 
              Ds[i[i_]] = {j[j_]:{l[l_]:'some value'}}
  </code></pre>
  
  <p>I tried this, but this does not work. </p>
  
  <p><strong>Extra:</strong>
  I am writing a Linear program in <code>Pulp</code> and I want to create a dictionary of demand values for a particular sku <code>i</code>, in period <code>j</code> on line <code>l</code> so that I can do <code>Dijl*Xijtl = some_value</code> summed over <code>i</code>, <code>j</code> ,<code>l</code> for constraints or something like that. These demand values are constants. This could be cartesian product or comprehension. Is there a function similar to <code>LpVariable.dicts()</code>?</p>