title: How can I improve a file line count counting lines according to categories in python
body: <h3>Code</h3>
  <pre><code>def countqa(mdFile):
    result = []
    tailf=tail(mdFile)
  
    with open(mdFile, 'r') as f:
      qcounter = 0
      acount = 0
      for line in f:
  
          if line in '\n' or line in ' \n':
              continue
  
          if '####' in line:
  
              qcounter += 1
              if qcounter==2:
                  result.append(acount)
  
              elif qcounter&gt;1:
                  result.append(acount)
   
              acount = 0
              continue
             
          acount += 1
          if line== tailf:
                  result.append(acount)
              
    return teststr
  
  print(countqa('example.md'))
  </code></pre>
  <h3>mdFile:</h3>
  <pre><code>#### Question 1?
  
  This is the answer 1
  
  second answer
  
  #### Another question 2?
  
  Another answer 2
  
  #### Question 3?
  
  Answer 1
  
  Answer 2
  
  The Answer 3
  </code></pre>
  <h3>Result:</h3>
  <p>[213]</p>
  <h3>Expected output = Real Output</h3>
  <p>Count the number of questions and answers of a text file:</p>
  <h3>Preconditions</h3>
  <p>tail() returns the last line of the file.</p>
  <p>Questions have #### at the front, answers (and code) not</p>
  <h3>What I want</h3>
  <p>How can it be improved? One issue is that the last line has to be unique, otherwise it gets a wrong result. The creation of the final list with the number of answers of each question is a hack, and difficult to read.</p>