title: Comparing 40 million lines in a file with 6 million list items in Python
body: <p>I have a file with 40 million entries in the form of:</p>
  
  <pre><code>#No Username
  </code></pre>
  
  <p>And I have a list with 6 million items, where each item is a username.</p>
  
  <p>I want to find the common usernames in the fastest way possible. Here’s what I’ve got so far:</p>
  
  <pre><code>import os
  usernames=[]
  common=open('/path/to/filf','w')
  f=open('/path/to/6 million','r')
  for l in os.listdir('/path/to/directory/with/usernames/'):
      usernames.append(l)
  #noOfUsers=len(usernames)
  for l in f:
      l=l.split(' ')
      if(l[1] in usernames):
          common.write(l[1]+'\n')
  common.close()
  f.close()
  </code></pre>
  
  <p>How can I improve the performance of this code?</p>