if does not evaluate

Robert Brewer fumanchu at amor.org
Sun Jun 6 06:49:34 CEST 2004

Jim Newton wrote:
> how do you put an if or a for inside a lambda?

Example? The answer to that (using current syntax) depends upon the
use-case. Short answer: don't use lambdas for that; use a full function.

> The expression i'm suggesting as evaluatable
> could be passable to a function call as well,
> as being mappable, or usable inside a lambda.
> It seems better to me in that it stops being
> a special case.
> E.g.,
> myfun( ( if cond1 expr1: else expr2 ),
>         ( if cond2 expr3: else expr4 ))

I'm not sure what "it" is that is a "special case". The lambda?

Have you read PEP 308, by the way?
http://www.python.org/peps/pep-0308.html You'll notice that the
community doesn't lack for syntax proposals to implement ternary
operations. Indeed, there are perhaps too many. ;) Many of those have
patches ready to go. The sticking point is currently more social than

Robert Brewer
Amor Ministries
fumanchu at amor.org

More information about the Python-list mailing list