title: The most efficient way to build a deep nested dictionary from a list of dictionary in Python
body: <p>I have a list of dictionaries <code>l</code>, each of them is a simple 1-level dictionary with the same keys <code>a</code>, <code>b</code>, <code>c</code>, <code>d</code>.<br>
  Now I want to build a nested dictionary from <code>l</code> in this shape (<code>i</code> is an member of <code>l</code>):</p>
  
  <pre><code>{
      i['a']: {
          i['b']: {
              i['c']: {
                  i['d']: some_value,
              }
          }
      }
  }
  </code></pre>
  
  <p>Right now I'm using this snippet:</p>
  
  <pre><code>tmp = {}
  for i in l:
      if not i['a'] in tmp:
          tmp[i['a']] = {}
      if not i['b'] in tmp[i['a']]:
          tmp[i['a']][i['b']] = {}
      if not i['c'] in tmp[i['a']][i['b']]:
          tmp[i['a']][i['b']][i['c']] = {}
      tmp[i['a']][i['b']][i['c']][i['d']] = some_value
  </code></pre>
  
  <p>Is that the most efficient way if the original list is huge?</p>