title: Create nested dictionaries with for loop in Python
body: <p>I have been trying create a dictionary that is made of dictionaries, while importing their values from a csv file.</p>
  
  <p>Assume that I have 3 csv files, each for a different Rating (150,300,600) that are similar to this:</p>
  
  <pre><code>6,100
  8,150
  10,200
  </code></pre>
  
  <p>For each Rating, I am trying to populate a corresponding dictionary, like this:</p>
  
  <pre><code>Rating={150,300,600}
  npd = {}
  temp={}
  flg={}
  flg150={}
  flg300={}
  flg600={}
  
  print(flg)
  for k in Rating:
      print(k)
      reader=csv.reader(open(str(k)+'.csv'))
      for x in reader:
          key=x[0]
          temp[key]=x[1]
      print(temp) 
      flg[k]=temp
      print(flg[k])
  print(flg)
  </code></pre>
  
  <p>I thought of creating one compound dictionary ie</p>
  
  <blockquote>
    <p>flg={150:{6:100,8:150,....},300{6:140,8:160...}, etc, etc}</p>
  </blockquote>
  
  <p>and then assign the values to separate dictionaries:</p>
  
  <blockquote>
    <p>flg150=flg.get(150)</p>
  </blockquote>
  
  <p>The problem is that when I run it, the flg dict ends up with the same value for all of its keys.</p>
  
  <pre><code>{}
  600
  {'8': '210', '6': '160', '10': '260'}
  {'8': '210', '6': '160', '10': '260'}
  300
  {'8': '190', '6': '140', '10': '240'}
  {'8': '190', '6': '140', '10': '240'}
  150
  {'8': '170', '6': '120', '10': '220'}
  {'8': '170', '6': '120', '10': '220'}
  {600: {'8': '170', '6': '120', '10': '220'}, 300: {'8': '170', '6': '120', '10': '220'}, 150: {'8': '170', '6': '120', '10': '220'}}
  </code></pre>
  
  <p>What am I doing wrong here? And is there a way to make this a bit more elegant, because it looks kind of ugly to me...?</p>