checking if a list is empty
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Mon May 9 19:34:59 EDT 2011
On Mon, 09 May 2011 16:58:14 -0500, harrismh777 wrote:
> Ian Kelly wrote:
>> "bool(list)" describes whether the list contains something. "Not"
>> being a logical operator, it stands to reason that "not list" should
>> mean the same thing as "not bool(list)".
>
> Ian, James,
>
> Agreed, and thank you. This *is* the explanation I was trying to
> prompt D'Aprano for, rather than getting his 'not cat' analogy.
Your dislike of analogies is leading you to see them where they aren't.
The "cat on the mat" sentence I gave is a concrete example of the use of
negation in English, not an analogy. It is virtually the opposite of an
analogy.
In that same post that annoyed you with the cat on the mat example, I
wrote:
Python uses a boolean algebra where there are many ways of
spelling the true and false values. The "not" operator returns
the canonical bool values:
not <any true value> returns False
not <any false value> returns True
Take note of the distinction between lower-case true/false,
which are adjectives, and True/False, which are objects of
class bool.
and later on, I contrasted:
empty list versus non-empty list
Ergo, "not (empty list)" returns True, and "not (non-empty list)" returns
False, because the empty list is considered false and any non-empty list
is considered true. I'm sorry that I failed to make that more explicit.
If I were talking to a programming n00b, I would have been more careful,
but you've made numerous references to your long, long programming
experience and I thought you would be able to draw the obvious connection
without me insulting you by stating the obvious.
--
Steven
More information about the Python-list
mailing list