A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2004-May/044717.html below:

[Python-Dev] horrible thought

[Python-Dev] horrible thoughtNick 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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4