Inline Conditionals?
JCM
joshway_without_spam at myway.com
Thu Aug 26 10:46:22 EDT 2004
Antoon Pardon <apardon at forel.vub.ac.be> wrote:
> Op 2004-08-26, Alex Martelli schreef <aleaxit at yahoo.com>:
...
>> Peter's right. And Joshua's example shows how wise the BDFL was in
>> ruling out ternaries: sure, good programmers might occasionally have
>> found good uses for them, but we' have paid that with a LOT of horrid
>> code like that -- I've seen lots like that in C & its ilk, too.
> When using list comprehension not having a ternary operator can be
> a PITA. It is of course possible I miss something but how am I
> supposed to do the following:
> [ x.property ? foo(x) : bar(x) for x in Somelist ]
def foo_or_bar(x):
if x.property:
return foo(x)
return bar(x)
[foo_or_bar(x) for x in Somelist]
(still, I'd like to see a ternary conditional operator too...)
More information about the Python-list
mailing list