title: Is there a faster way to loop through this code?
body: <p>I have a long list of generated names, and a 5000 word file containing acceptable names. I want to find the names in my list that also appear on the file. How do I do this?</p>
  
  <p>I've tried using a loop, but that takes too long for what I need, because my file of names is too long to search through the whole file for each generated name. When n is 12 numbers long, there are 531441 names in my generated list.</p>
  
  <p>Here is some code:</p>
  
  <pre class="lang-py prettyprint-override"><code>from time import process_time
  from itertools import product
  start = process_time()
  n = "5747867437"
  phone = {2: ["A", "B", "C"], 3: ["D", "E", "F"], 4: {"G", "H", "I"}, 5: ["J", "K", "L"], 6: ["M", "N", "O"], 7: ["P", "R", "S"], 8: ["T", "U", "V"], 9: ["W", "X", "Y"]}
  li = set(open("dict.txt", "r").read().strip().split("\n"))
  num = []
  names = []
  for x in n:
      num.append(phone[int(x)])
  for y in product(*num):
      names.append(''.join(y))
  available = []
  ad = False
  for z in names:
      if z in li:
          available.append(z)
  acceptable.sort()
  print(acceptable)
  if acceptable:
      for a in acceptable:
          print(a + "\n")
  else:
      print("NONE\n")
  print(process_time() - start)
  
  </code></pre>
  
  <p>The file "acceptable_names.txt" is the file with the acceptable names in it.
  Right now it takes 3 seconds. Is there a way to make this faster?</p>
  
  <p>Thanks in advance!</p>