rhodri at wildebst.demon.co.uk
Sat Mar 7 02:43:33 CET 2009
On Fri, 06 Mar 2009 15:34:08 -0000, Grant Edwards <invalid at invalid> wrote:
> On 2009-03-06, Fencer <no.spam at plz.ok> 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
> I'd do it like this:
> b = (n is not None) and (n != )
The second comparison isn't actually necessary, since an
empty list is True and a non-empty one False.
b = (n is not None) and n
Putting the comparison in does make the code slightly less
"magic", though, so it's not a bad idea to do it!
Rhodri James *-* Wildebeeste Herder to the Masses
More information about the Python-list