title: Comparing Two CSV in Python
body: <p>I am formatting CSV in Python to get the desired result but my code doesn't seem to work properly.</p>
  
  <p>I have the first CSV file in format:</p>
  
  <pre><code>2,a
  1,a
  4,a
  5,a
  3,a
  1,a
  3,b
  2,b
  1,a
  </code></pre>
  
  <p>The second CSV file in format:</p>
  
  <pre><code>1,a,123
  1,a,234
  2,a,456
  2,b,345
  3,a,789
  3,b,232
  4,a,987
  </code></pre>
  
  <p>As the first CSV file is not sorted, the second CSV file is sorted in increasing order with respect to first column</p>
  
  <p>I want the output in format:</p>
  
  <pre><code>2,a,456
  1,a,123
  4,a,987
  5,a
  3,a,789
  1,a,234
  3,b,232
  2,b,345
  1,a
  </code></pre>
  
  <p>The result is printed in respect to the first CSV, if the first CSV file combination is not found in the second CSV File, for example if <code>5,a</code> is not in the second CSV file then just <code>5,a</code> is printed in its respected position. The first CSV file contains many duplicates, while in the second CSV file each row is unique.</p>
  
  <p>Here is my Code</p>
  
  <pre><code>for (num,alpha) in first_csv:
      value_found = True
      for (num1,alpha1,num2) in second_csv:
          if (num == num1 and alpha == alpha1):
              csv_out +=  str(num) + ',' + str(alpha) + ',' + str(number)
              value_found = False
      if value_found:
          count+=1
          if count == 1:
              csv_out += str(num) + ',' + str(alpha)
  </code></pre>
  
  <p>first_csv and second_csv are tuples I have created after reading the CSV files with the code:</p>
  
  <pre><code>with open('first_csv.csv') as f:
      f.readline()
      first_csv = tuple(csv.reader(f, delimiter=','))
  
  
  with open('second_csv.csv') as f:
      f.readline()
      second_csv = tuple(csv.reader(f, delimiter=','))
  </code></pre>
  
  <p>But it is not printing the desired output, where am I doing wrong?</p>