title: Compare data from 2 files having million records in Python
body: <p>I have 2 files old.txt and new.txt containing hundreds of thousands of data(near about 1.2 million keys and respective amounts)</p>
  
  <p>new.txt</p>
  
  <pre><code>key |amount
  abgc-nhd|8976
  mkis-plqa-d|-254
  mjsnh-kis-ls|987
  njud-lo-sa|5291
  mkjsh-kis-ls|686
  mjsnh-fis-ls|387
  njudd-kid-ls|-876
  nswxd-lo-sa|3191
  mki-ksjd-as|-56
  </code></pre>
  
  <p>old.txt</p>
  
  <pre><code>key |amount
  mkjsh-kis-ls|686
  njudd-kid-ls|-876
  abgc-nhd|8976
  mjsnh-kis-ls|987
  njud-lo-sa|5291
  mjsnh-fis-ls|387
  mkis-plqa-d|-254
  nswxd-lo-sa|3191
  </code></pre>
  
  <p>I want to compare these two files.</p>
  
  <p>i.e.I want to check whether the key in the old file matches the key in the new file.If yes then i have to compare their amount.</p>
  
  <p>I tried by inserting all values into a dictionary and then checking whether the entries exists,but this takes a longer time and the system gets hanged.</p>
  
  <p>Is there any another way to compare the two file on the basis of key.</p>
  
  <p>Thanks.</p>