title: find line index in a text file python
body: <p>I want to get the index of the line that corresponds to a certain string (in this case, InChI=1S/C11etc..) in a text file (content), here is my code:</p>
  
  <pre><code>with open('compounds.dat', encoding='utf-8', errors='ignore') as f:
      content = f.readlines()
      index = [x for x in range(len(content)) if "InChI=1S/C11H8O3/c1-6-5-9(13)10-7(11(6)14)3-2-4-8(10)12/h2-5" in content[x].lower()]
      print(index)
  </code></pre>
  
  <p>However I get empty bracket []. But I am pretty sure that the line exist, because if I run this:</p>
  
  <pre><code>for line in f:
      if u"InChI=1S/C11H8O3/c1-6-5-9(13)10-7(11(6)14)3-2-4-8(10)12/h2-5" in line:
          l = line
  </code></pre>
  
  <p>I get the line I am interested.</p>