title: How do you create nested dict in Python?
body: <p>I have 2 CSV files: 'Data' and 'Mapping':</p>
  
  <ul>
  <li>'Mapping' file has 4 columns: <code>Device_Name</code>, <code>GDN</code>, <code>Device_Type</code>, and <code>Device_OS</code>. All four columns are populated.</li>
  <li>'Data' file has these same columns, with <code>Device_Name</code> column populated and the other three columns blank. </li>
  <li>I want my Python code to open both files and for each <code>Device_Name</code> in the Data file, map its <code>GDN</code>, <code>Device_Type</code>, and <code>Device_OS</code> value from the Mapping file.</li>
  </ul>
  
  <p>I know how to use dict when only 2 columns are present (1 is needed to be mapped) but I don't know how to accomplish this when 3 columns need to be mapped.</p>
  
  <p>Following is the code using which I tried to accomplish mapping of <code>Device_Type</code>:</p>
  
  <pre><code>x = dict([])
  with open("Pricing Mapping_2013-04-22.csv", "rb") as in_file1:
      file_map = csv.reader(in_file1, delimiter=',')
      for row in file_map:
         typemap = [row[0],row[2]]
         x.append(typemap)
  
  with open("Pricing_Updated_Cleaned.csv", "rb") as in_file2, open("Data Scraper_GDN.csv", "wb") as out_file:
      writer = csv.writer(out_file, delimiter=',')
      for row in csv.reader(in_file2, delimiter=','):
           try:
                row[27] = x[row[11]]
           except KeyError:
                row[27] = ""
           writer.writerow(row)
  </code></pre>
  
  <p>It returns <code>Attribute Error</code>.</p>
  
  <p>After some researching, I think I need to create a nested dict, but I don't have any idea how to do this.  </p>