pythonian way

Alexander Williams thantos at chancel.org
Fri Feb 25 04:26:33 EST 2000


On Fri, 25 Feb 2000 09:49:15 +0100, Milos Prudek <prudek at nembv.cz> wrote:
>>     A = H.readlines()
>
>Yeah, but I need to remove empty lines as well...

Try:

   >>> A = filter(None, H.readlines())

filter() with None as the function to use as the test for elements
removes any that test as False intrinsically; since the empty line is
always False, it returns a list with only strings with length.  Bingo.

-- 
Alexander Williams (thantos at gw.total-web.net)           | In the End,
  "Join the secret struggle for the soul of the world." | Oblivion
  Nobilis, a new Kind of RPG                            | Always
  http://www.chancel.org                                | Wins



More information about the Python-list mailing list