[Python-Dev] horrible thought
Nick Coghlan
ncoghlan at iinet.net.au
Fri May 7 08:18:17 EDT 2004
David Abrahams wrote:
> Remember the vote on adding conditional expressions?
>
> I'm afraid that the imminent proliferation of xxxcomps may indicate
> the "right" syntax for this feature, if it ever does get added.
>
> Something like
>
> (a else b if condition)
>
> Now I've done my bad deed for the day.
That's actually an interesting thought. Is there anything to be learned
about conditionals by considering the syntactic sugar for list comps and
gen comps?
List comp [f(x) for x in original if p(x)]:
def _result(f, p, original):
lc = []
for x in original:
if p(x):
lc.append(f(x))
return lc
Gen comp (f(x) for x in original if p(x)):
def _result(f, p, original):
for x in original:
if p(x):
yield f(x)
Conditional (syntactic sugar not defined):
def _result(a, b, p):
if p:
return a
else:
return b
Nope, still suggests (a if p else b) to me.
With nesting then being (a if p1 else b if p2 else c if p3 else d).
OK, done now. We can just let that discussion go back into its box. . .
Regards,
Nick.
--
Nick Coghlan | Brisbane, Australia
Email: ncoghlan at email.com | Mobile: +61 409 573 268
More information about the Python-Dev
mailing list