On Sat, 07 Mar 2009 05:03:08 -0000, Grant Edwards <gra...@visi.com> wrote:

On 2009-03-07, Rhodri James <rho...@wildebst.demon.co.uk> wrote:
On Fri, 06 Mar 2009 15:34:08 -0000, Grant Edwards <inva...@invalid> wrote:

On 2009-03-06, Fencer <no.s...@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!

Putting in the second comparison in makes the code match the
stated requirement.  Otherwise you have to start making
assumptions about what n might be besides None or the empty
list.

The OP stated that we *could* assume that n was None or a
list, so I stand by what I said.

--
Rhodri James *-* Wildebeeste Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to