title: Compare two CSV files and look for matches Python
body: <p>I have two CSV files that are like</p>
  
  <p>CSV1</p>
  
  <pre><code>H1,H2,H3
  arm,biopsy,forearm
  heart,leg biopsy,biopsy
  </code></pre>
  
  <p>organs.csv</p>
  
  <pre><code>arm
  leg
  forearm
  heart
  skin
  </code></pre>
  
  <p>I need to compare both the files and get an output list like this [arm,forearm,heart,leg] but the script that I'm currently working on doesn't give me any output (I want leg also in the output, though it is mixed with biopsy in the same cell). Here's the code so far. How can I get all the matched words?</p>
  
  <pre><code>import csv
  import io
  
  alist, blist = [], []
  
  with open("csv1.csv", "rb") as fileA:
      reader = csv.reader(fileA, delimiter=',')
      for row in reader:
          alist.append(row)
  with open("organs.csv", "rb") as fileB:
      reader = csv.reader(fileB, delimiter=',')
      for row in reader:
          blist.append(row)
  
  first_set = set(map(tuple, alist))
  secnd_set = set(map(tuple, blist))
  
  matches = set(first_set).intersection(secnd_set)
  print matches
  </code></pre>