![]() |
Available news archives:
comp.lang.tcl
-
comp.lang.python
-
comp.security.firewalls
-
sci.crypt -
comp.lang.php -
comp.lang.javascript
|
|
comp.lang.python archiveRe: Is there something similar to ?: operator (C/C++) in Python?
From: Ron Adam <rrr@ronadam.com>
Date: Thu Jun 30 2005 - 20:19:26 CEST
Antoon Pardon wrote:
That works as long as long as they are expressions, but the ? format
To use *any* expressions in a similar way we need to use eval which is a
result = eval(['expr0','expr1'][cond])
A thought occurs to me that putting index's before the list might be an
result = expr[expr0,expr1]
This would probably conflict with way too many other things though.
result = index from [expr0,expr1]
Where index can be an expression. That is sort of an inline case
result = condition from {True:expr1, False:expr0}
As a case using values as an index:
case expr from [
Or using strings with a dictionary...
case expr from {
Reads nice, but can't put expressions in a dictionary or list without
Can't help thinking of what if's. ;-)
Cheer's
|