create boolean

Scott David Daniels Scott.Daniels at Acm.Org
Sat Mar 7 13:07:56 EST 2009


Lie Ryan wrote:
> Fencer wrote:
> The literal translation of that would be:
> if n is not None and n != []:
>     b = True
> else:
>     b = False
> it is a bit verbose, so one might want to find something shorter
> b = True if n is not None and n != [] else False
> I always feel if and in-line if to be easier and more readable than 
> short-circuited operations.

How about:
    b = None is not n != []

It is amazing to think about how rarely we consider is / is not as
a comparison operator.  Also, and more reasonably, we often don't
consider "chaining" comparisons that are intransitive.

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list