title: How to remove leftmost/rightmost elements in list that satisfy a certain criterion in python?
body: <p>I have a list that looks like this: </p>
  
  <p><code>['a', 'b', 'c', '', '', '']</code></p>
  
  <p>This is the result of parsing a 'dirty' csv file. I now want to get rid of the empty columns on the right. I cannot just use counting, because the length is variable. I also cannot just use simple filtering, because there are also rows that look like this:</p>
  
  <p><code>['a1', '', 'c1', '', '']</code></p>
  
  <p>So I have to preserve the empty columns that are <strong>not</strong> at the very right. Is there an idiomatic way to do this? I am hoping for something like a "removeWhile" function that I could apply on the reversed list.</p>
  
  <p>The best I've come up with so far is the following:</p>
  
  <pre><code>def filterRow(row):
      row.reverse()
      blanks = 0
      for x in row:
          if x == '':
              blanks += 1
          else:
              break
      row.reverse()
      return row[0:-blanks]
  </code></pre>