conditionals in lambdas?

Michael P. Soulier msoulier at nortelnetworks.com
Fri Nov 3 16:39:41 EST 2000


In article <XoFM5.4146$jv2.475484 at newsc.telia.net>, 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. 

    Thanks,

    Mike

-- 
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) http://nlug.ca.nortel.com



More information about the Python-list mailing list