title: Fastest way to grep multiple values from file in python
body: <ul>
  <li>I have a file of 300m lines (inputFile), all with 2 columns separated by a tab. </li>
  <li>I also have a list of 1000 unique items (vals).</li>
  </ul>
  
  <p>I want to create a dictionary with column 1 as key and column 2 as value for all lines in <em>inputFile</em> where the first columns occurs in <em>vals</em>. A few items in <em>vals</em> do not occur in the file, these values have to be saved in a new list. I can use up to 20 threads to speed up this process.</p>
  
  <p>What is the fastest way to achieve this?</p>
  
  <p>My best try till now: </p>
  
  <pre><code>newDict = {}
  foundVals = []
  cmd = "grep \"" + vals[0]
  for val in vals:
       cmd = cmd + "\|^"+val+"[[:space:]]"
  cmd = cmd + "\" " + self.inputFile
  p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  for line in iter(p.stdout.readline, ''):
      info = line.split()
      foundVals.append(info[0])
      newDict.update({info[0]:info[1]})
  p.wait()
  notFound = [x for x in vals if x not in set(foundVals)]
  </code></pre>
  
  <p><strong>Example</strong> 
  inputFile:</p>
  
  <pre><code>2       9913
  3       9913
  4       9646
  ...
  594592886       32630
  594592888       32630
  594592890       32630
  </code></pre>
  
  <p>vals: </p>
  
  <pre><code>[1,2,594592888]
  </code></pre>
  
  <p>wanted dictionary:</p>
  
  <pre><code>{2:9913,594592888:32630}
  </code></pre>
  
  <p>And in notFound:</p>
  
  <pre><code>[1]
  </code></pre>