title: I am creating a dict from a file with duplicate values. How do I prevent my loop overwriting existing values?
body: <p>I'm having a real headache with a python script.</p>
  
  <p>It basically loads a DNS zone like txt file that looks like this:</p>
  
  <pre><code>name.com 3600 MX ns1.google.com
  name1    3600 A  1.2.3.4
  </code></pre>
  
  <p>I am loading this file into python, looping through each line and converting each line to a list, so the above data would look like this:</p>
  
  <pre><code>[["name.com", "3600", "MX", "ns1.google.com"],["name1","3600","A","1.2.3.4"]] etc
  </code></pre>
  
  <p>I then need to take each list and assign bits of data to a dict like so:</p>
  
  <pre><code>for each_list in data:
       terrarecord[each_list[0].replace('.', '') + str(self.random)] = {
                  "zone_id": self.zone_id,
                  "name": each_list[0] + self.url, 
                  "type": each_list[2],
                  "ttl": each_list[1],
                  "records": [each_list[3].replace('\n', '')]
              }
  </code></pre>
  
  <p>which for the above example text file is all fine and dandy. However if I have a zone file with duplicate entries such as below, this loop is writing over them causing all sorts of havoc.</p>
  
  <pre><code>name.com 3600 MX ns1.google.com
  name1    3600 A  1.2.3.4
  name1    2000 A  1.2.2.2 # &lt;--- this will overwritten
  </code></pre>
  
  <p>How can I write this loop so it creates a new dict object each time instead of writing over an existing dictionary?</p>