title: Finding substrings in a certain order in python
body: <p>I have a long list of strings which contain substrings of interest in the order they are given, but here is a small example using sentences in a text file:</p>
  
  <pre><code>This is a long drawn out sentence needed to emphasize a topic I am trying to learn.
  It is new idea for me and I need your help with it please!
  Thank you so much in advance, I really appreciate it.
  </code></pre>
  
  <p>From this text file, I would like to find any sentences that contain both <code>"I"</code> and <code>"need"</code> but they must occur in that order.</p>
  
  <p>So in this example, <code>'I'</code> and <code>'need'</code> both occur in sentence 1 and sentence 2 but in sentence 1 they are in the wrong order, so I do not want to return that. I only want to return the second sentence, as it has <code>'I need'</code> in order. </p>
  
  <p>I have used this example to identify the substrings, but I cannot figure out how to only find them in order:</p>
  
  <pre><code>id1 = "I"
  id2 = "need"
  
  with open('fun.txt') as f:
      for line in f:
          if id1 and id2 in line:
              print(line[:-1])
  </code></pre>
  
  <p>This returns:</p>
  
  <pre><code>This is a long drawn out sentence needed to emphasize a topic I am trying to learn.
  It is new idea for me and I need your help with it please!
  </code></pre>
  
  <p>But I want only:</p>
  
  <pre><code>It is new idea for me and I need your help with it please!
  </code></pre>
  
  <p>Thanks!</p>