conditionals in lambdas?

Michael P. Soulier msoulier at
Fri Nov 3 22:39:41 CET 2000

In article <XoFM5.4146$jv2.475484 at>, Fredrik Lundh wrote:
>oh, but "string[:9] == '#LOADDATA' is an expression, which
>returns zero if false, and a non-zero (1, actually) if true.
>try this:
>    filter(lambda s: s[:9] == '#LOADDATA', filecontents)
>or better:
>    filter(lambda s: s.startswith('#LOADDATA'), filecontents)
>or, if you're using 2.0:
>    [line for line in filecontents if line.startswith('#LOADDATA')]

    Ah, gotcha. 



Michael P. Soulier, TD12, SKY  Tel: 613-765-4699 (ESN: 39-54699)
Optical Networks, Nortel Networks, SDE Pegasus
"...the word HACK is used as a verb to indicate a massive amount
of nerd-like effort."  -Harley Hahn, A Student's Guide to UNIX
Nortel Linux User's Group Ottawa: (internal)

More information about the Python-list mailing list