checking if a list is empty

Chris Torek nospam at torek.net
Wed May 11 23:49:05 EDT 2011


In article <4dc6a39a$0$29991$c3e8da3$5496439d at news.astraweb.com>
Steven D'Aprano  <steve+comp.lang.python at pearwood.info> wrote:
>In English, [the word "not"] negates a word or statement:
>
>"the cat is not on the mat" --> "the cat is on the mat" is false.

As a mostly off topic aside, English is considerably more complicated
than that.  There are people who use the word "not" as a purely
boolean operator (a la computer languages), so that "the cat is
not not on the mat" means "the cat IS on the mat", but others use
double negation as a form of intensifier, so that the phrase with
multiple "not"s is simply a more emphatic claim: the cat is really,
truly, *definitely*, not on that particular mat. :-)

In various other "natural languages" -- i.e., languages meant for
human-to-human communications, rather than for computers -- multiple
negatives are more often (or always?) intensifiers.  Some languages
have the idea of "negative matching" in much the same sense that
English has number [%] matching: "the cat is on the mat" and "the cats
are on the mat" are OK because the noun and verb numbers match,
but neither "the cats is on the mat" nor "the cat are on the mat"
are correct.

[% "Number" here is really 1 vs not-1: no cats, one cat, two cats.]

Of course, there are descriptivists and prescriptivists, and many
of the latter claim that using multi-valued boolean logic in English
is "nonstandard" or "invalid".  Many of those in turn will tell
you that "ain't good English" ain't good English.  Still, one should
be aware of these forms and their uses, in much the same way as
one should be able to boldly split infinitives. :-)

Moving back towards on-topic-ness:

>As an operator, "not" negates a true value to a false value. In 
>mathematical Boolean algebra, there only is one true value and one false 
>value, conventionally called True/False or 1/0. In non-Boolean algebras, 
>you can define other values. In three-value logic, the negation of True/
>False/Maybe is usually False/True/Maybe. In fuzzy logic, the logic values 
>are the uncountable infinity (that's a technical term, not hyperbole) of 
>real numbers between 0 and 1.

Or, to put it another way, before we can communicate clearly, we have
to pick out a set of rules.  Most computer languages do this pretty
well, and Python does a good (and reasonably conventional) job:

>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.

(At least as of current versions of Python -- in much older versions
there was no real distinction between booleans and type "int",
presumably a a holdover from C.)

[remainder snipped as I have nothing else to add]
-- 
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W)  +1 801 277 2603
email: gmail (figure it out)      http://web.torek.net/torek/index.html



More information about the Python-list mailing list