create boolean
Lie Ryan
lie.1296 at gmail.com
Sat Mar 7 04:38:34 EST 2009
Fencer wrote:
> Hi, I need a boolean b to be true if the variable n is not None and not
> an empty list, otherwise b should be false.
> I ended up with:
> b = n is not None and not not n
> which seems to work but is that normally how you would do it?
> It can be assumed that n is always None or a list that might be empty
>
> - Fencer
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.
More information about the Python-list
mailing list