title: How to remove lines from a file starting with a specific word python3
body: <p>I am doing this as an assignment. So, I need to read a file and remove lines that start with a specific word.</p>
  <pre><code>fajl = input(&quot;File name:&quot;)
  rec = input(&quot;Word:&quot;)
          
  def delete_lines(fajl, rec):
      with open(fajl) as file:
          text = file.readlines()
          print(text)
          for word in text:
              words = word.split(' ')
              first_word = words[0]
              for first in word:
                  if first[0] == rec:
                      text = text.pop(rec)
                      return text
                      print(text)
                  return text
  
  delete_lines(fajl, rec)
  </code></pre>
  <p>At the last for loop, I completely lost control of what I am doing. Firstly, I can't use pop. So, once I locate the word, I need to somehow delete lines that start with that word. Additionally, there is also one minor problem with my approach and that is that first_word gets me the first word but the , also if it is present.</p>
  <p>Example text from a file(file.txt):</p>
  <p>This is some text on one line.</p>
  <p>The text is irrelevant.</p>
  <p>This would be some specific stuff.</p>
  <p>However, it is not.</p>
  <p>This is just nonsense.</p>
  <pre><code>rec = input(&quot;Word:&quot;) --- This
  </code></pre>
  <p>Output:</p>
  <p>The text is irrelevant.</p>
  <p>However, it is not.</p>