title: Converting list of lists into a dictionary of dictionaries in Python
body: <p>I am trying to convert a list of lists data structure to a dictionary of dictionaries.</p>
  
  <p>The list is defined as follows:</p>
  
  <pre><code>l = [
    ['PP','Ear-rings', 'Holesovice', 2000],
    ['PP','Skirts', 'Holesovice', 1000],
    ['PP','Dresses', 'E-shop', 1500],
    ['BM','Butterfly', 'Holesovice', 1600]
  ]
  </code></pre>
  
  <p>My aim is to have the dictionary structure as follows:</p>
  
  <pre><code>#{'PP' : {'Holesovice' : {'Ear-rings' : 2000, 'Skirts' : 1000},
  #         'E-shop' : {'Dresses' : 1500}},
  # 'BM' : {'Holesovice' : {'Butterfly' : 1600}}
  #}
  </code></pre>
  
  <p>This bit of code does not return desired output:</p>
  
  <pre><code>labels_d = {}
  items_d = {}
  shops_d = {}
  
  for index, row in enumerate(l):
    items_d[row[1]] = row[3]
    shops_d[row[2]] = items_d
    labels_d[row[0]] = shops_d
  
  print(labels_d)
  </code></pre>
  
  <p>I found some posts that deal with converting lists to dictionaries <a href="https://stackoverflow.com/questions/30193942/converting-list-of-lists-of-lists-into-dictionary-of-dictionaries-python">here</a> and <a href="https://stackoverflow.com/questions/34191817/python-list-of-lists-to-dictionary">here</a> but I did not make it work the way I want. Is there any 'clean' way how to achieve the structure posted above?</p>