[Python-Dev] Trinary Operators
Samuele Pedroni
pedronis@bluewin.ch
Fri, 7 Feb 2003 17:21:10 +0100
From: "Guido van Rossum" <guido@python.org>
> > Oh dear. If you are really going to do these these cutesy English-like
> > expressions I'd have to resurrect my old proposal of:
> >
> > if CONDITION for some NAME in ITERABLE:
> > if CONDITION for every NAME in ITERABLE:
> > if CONDITION for no NAME in ITERABLE:
> >
> > Please, dont make me do that ;-)
>
> An if-expression is frequently requested, and I expect people will
> continue to ask for it until I add one :-)
>
> Who (besides you) has ever asked for generalized quantifiers? They
> were in ABC, with slightly different syntax:
>
I would not dislike to have expression forms equivalent to applications of
def every(pred,l):
for x in l:
if not pred(x): return False
return True
def some(pred,l):
for x in in l:
if pred(x): return True
return False
def such(pred,l,otherwise=None):
for x in in l:
if pred(x): return x
return otherwise
as list comprehension is equivalent to map and filter.