title: Compare two csv files to ouput the matches Python
body: <p>I have a csv file called "organs.csv" and another csv file with lots of data. I'm comparing them to get matches among them. The latter file doesn't have any particular format so I don't know which column has data about organs. I've tried the below code to get matches but it has two issues. </p>
  
  <ol>
  <li>If csv2 has an organ in two columns, it appends to the list twice. </li>
  <li>If a row doesn't have any organ, it just ignores it. </li>
  </ol>
  
  <p>I'd like it to do the following:</p>
  
  <ol>
  <li>If a row has an organ, skip to the next one (limit one organ per row)</li>
  <li>If no organ is found, print something like "-"</li>
  </ol>
  
  <p>code:</p>
  
  <pre><code>import csv
  filename = "file.csv"
  complist, orglist = [], []
  fileA = open(filename, "rb")
  reader = csv.reader(fileA, delimiter=',')
  for row in reader:
      for row_str in row:
          complist.append(row_str)
  with open("organs.csv", "rb") as fileB:
      reader = csv.reader(fileB, delimiter='\n')
      for row in reader:
          orglist += row
          orglist = [x.lower() for x in orglist]
  org = open ("organ_matches.txt", "wb")
  org_writer = csv.writer(org)
  for s in complist:
      for xs in orglist:
          if xs in s:
              print &gt;&gt; org, xs
  org.close()
  orgfile = open ("organ_matches.txt" , "r")
  organ = orgfile.read()
  organ = organ.split("\n")
  organ = ",".join (organ)
  organ = organ.split(",")
  orgfile.close()
  print organ
  </code></pre>
  
  <p>csv1:</p>
  
  <pre><code>forearm
  leg
  abdomen
  </code></pre>
  
  <p>csv2:</p>
  
  <pre><code>h1,h2,h3,h4
  data1,forearm biopsy,tissue,cell
  data2,leg injury,tissue in leg,cell9
  data4,data,tissue4,cell6
  </code></pre>
  
  <p>It now prints:</p>
  
  <pre><code>['forearm','leg','leg']
  </code></pre>
  
  <p>Desired output:</p>
  
  <pre><code>['forearm','leg','-']
  </code></pre>