any() and all() on empty list?
Fri Mar 31 01:20:24 CEST 2006
Steven D'Aprano <steve at REMOVETHIScyber.com.au> writes:
> >> No, all(seq) is true if every element in seq is true. Surely that's a
> >> more intuitive definition than your definition by what you can't do.
> > They are different?
> Of course they are different -- they differ in the case of an empty
I don't think they differ in the case of an empty sequence. If the
sequence is empty, both statements are true.
> > By the definition, "all flying elephants are pink" and "all flying
> > elephants are non-pink" are both true statements, if that's what
> > you're asking. There is no contradiction.
> Of course there is a contradiction. The contradiction is that flying
> elephants are simultaneously pink and not pink.
Neither statement asserts the existence of any flying elephants
regardless of color, so neither statement contradicts the other
> If you don't understand why "Foo is Bar" and "Foo is not Bar" can't both
> be true simultaneously, I suggest you spend some time googling on
> "noncontradiction logic". To get you started, here's the Wikipedia entry:
"All flying elephants are pink" is not a statement of the form "Foo is
Bar". See <http://en.wikipedia.org/wiki/For_all>, as I've cited
several times. "All flying elephants are pink" simply means "there
are no non-pink flying elephants". "All flying elephants are
non-pink" similarly means "there are no pink flying elephants". The
statements don't contradict, and in fact both statements are true.
> if husband.stopped_beating_wife(): # returns True or False
> Pretty hard on the innocent husbands who never even beat their wife at all.
Correct. The code should not be written that way.
> In hacker culture, the Chinese word
> "mu" (literally "without") is sometimes used to mean "I cannot answer that
> question because your assumptions are not correct".
> In the case of all(seq), the correct answer is "mu".
I don't think it's that bad. We just have to spell out precisely what
the assumptions are, and we've done so.
More information about the Python-list