Since there was talk of if-then-else not being allowed in lambda expressions, the following is from "Dive into Python"
Bruno Desthuilliers
onurb at xiludom.gro
Fri Jul 21 08:13:52 EDT 2006
Peter Otten wrote:
> Ant wrote:
>
>
>>># python 2.5
>>>
>>>>>>a, b = "", 0
>>>>>>a if False else b
>>>
>>>0
>>>
>>>>>>a if True else b
>>>
>>>''
>>>
>>>Time to tear out that page. Really.
>>
>>Not quite - 2.5 hasn't been released in its final version yet, and many
>>projects I should imagine will take a while to upgrade.
>
>
> Ok, use
>
> if cond:
> value = ... # expression that must not be evaluated unless it absolutely
> # has to be
> else:
> value = ... # same thing
>
> which will withstand the test of time.
But isn't allowed in a lambda !-)
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"
More information about the Python-list
mailing list