title: How to find (if it exists) that line of a txt file where the searched strings match at the same time?
body: <p>I need to verify if there is a line where these 2 matches are met in the respective .txt :</p>
  <ul>
  <li>Line of the file named <code>file1.txt</code> that is equal to the input string1 <code>&quot;old apple&quot;</code>.</li>
  <li>Line of the file named <code>file2.txt</code> that is equal to the input string2 <code>&quot;on the floor&quot;</code>.</li>
  </ul>
  <p>For example, <code>file1.txt</code> have these lines:</p>
  <pre><code>juicy orange
  old apple
  rusty key
  old apple
  modern table
  old apple
  
  </code></pre>
  <p>And for example, <code>file2.txt</code> have these other lines:</p>
  <pre><code>in a box
  on the chair
  on the bed
  on the floor
  on the floor
  under the desktop
  
  </code></pre>
  <p>In this case the correct line would be line 4, that is, the one with index 3</p>
  <p>This is my code but I am having problems with the mutual matching requirement</p>
  <pre class="lang-py prettyprint-override"><code>string1 = &quot;old apple&quot;
  string2 = &quot;on the floor&quot;
  
  num_linea_data_field_1 = None
  num_linea_data_field_2 = None
  
  validation_data_field_1 = False
  validation_data_field_2 = False
  
  with open(&quot;file1.txt&quot;,&quot;r+&quot;) as f:
      lineas = [linea.strip() for linea in f.readlines()]
      if (string1 not in lineas):
          pass
      else:
          num_linea_data_field_1 = lineas.index(string1)
          validation_data_field_1 = True
  
  with open(&quot;file2.txt&quot;,&quot;r+&quot;) as f:
      lineas = [linea.strip() for linea in f.readlines()]
      if (string1 not in lineas):
          pass
      else:
          num_linea_data_field_2 = lineas.index(string2)
          validation_data_field_2 = True
  
  
  if(validation_data_field_1 == True and validation_data_field_2 = True):
      print(&quot;Mutual coincidence condition is satisfied with these inputs!&quot;)
  
  else:
      print(&quot;Mutual coincidence condition is not satisfied with these inputs!&quot;)
  </code></pre>
  <p>This code is failing in cases where one of the inputs matches but on different lines of the file.</p>
  <p>How could I approach this double matching algorithm?</p>