Feature suggestion -- return if true

Westley Martínez anikom15 at gmail.com
Tue Apr 12 16:05:38 CEST 2011


On Tue, 2011-04-12 at 12:44 +1000, Chris Angelico wrote:
> On Tue, Apr 12, 2011 at 12:20 PM, James Mills
> <prologic at shortcircuit.net.au> wrote:
> > On Tue, Apr 12, 2011 at 12:18 PM, Jason Swails <jason.swails at gmail.com> wrote:
> >> This is only true if n < 5.  Otherwise, the first returns None and the
> >> second returns False.
> >
> > Which is why I said:
> >
> > return expr or None
> >
> > But hey let's argue the point to death!
> 
> That's still not equivalent. "return expr or None" will always
> terminate the function. The OP's request was for something which would
> terminate the function if and only if expr is non-false.
> 
> Chris Angelico

def bs(x):
    while not x:
        <modify x>
    return x

Am I wrong here?




More information about the Python-list mailing list