conditionals in lambdas?

Paul Prescod paulp at ActiveState.com
Fri Nov 3 17:29:51 EST 2000


Niki Spahiev wrote:
> 
> ...
>
> And why not this
> 
>  filecontents = open(filename, "r").readlines()
>  filecontents = filter(lambda s: s[:9] == '#LOADDATA', filecontents)

If you're using Python 2, here's a more verbose, but perhaps more
readable way to do the same thing:

filecontents = [line for line in filecontents 
                     if line.startswith("#LOADDATA")]

 Paul Prescod




More information about the Python-list mailing list