title: Checking for overlaps in two long lists of items in Python
body: <p>I have two lists (list1 and list2) that contain 10 million names of companies. Each list has no duplicates, but some companies appear in both lists. And I want to find what those companies are. I wrote the code below:</p>
  
  <pre><code>list_matched = []
  for i in range(len(list1)):
      for j in range(len(list2)):
          if list1[i] == list2[j]:
              list_matched.append(list1[i])
  </code></pre>
  
  <p>The problem of this code is that it never finishes executing. My question is what I can do to finish this task within a reasonable amount of time. The size of 10 million names seems to be too big to handle.</p>