title: What is the fastest way to check if a sentence contains items in a list?
body: <p>There is a file with 90,000+ lines and a list (called "entity_list") with 40,000+ entities. I am trying to identify if a line contains items in the list. If yes, locating items' locations (start position: "start", end position: "end") and replacing them with "new_item"</p>
  
  <p>I have tried two for-loop operations. I use regular expressions to locate items, but it is not shown in the following code.</p>
  
  <pre class="lang-py prettyprint-override"><code>for line in file.readlines():
      for entity in entity_list:
          if entity in line:
               line = line.replace(line[start:end], new_item)
  </code></pre>
  
  <p>However, it is really slow. Is it a faster way to do it? Any help would be appreciated.</p>