Re: any(), all() and empty iterable

2009-04-20 Thread John O'Hagan
On Mon, 20 Apr 2009, Antoon Pardon wrote: > On 2009-04-15, John O'Hagan wrote: > > On Tue, 14 Apr 2009, Mark Dickinson wrote: [...] > >> I'd like to guess that in 93.7% of cases, when a programmer > >> has used all(seq) without having thought in advance about what the > >> right thing to do is

Re: any(), all() and empty iterable

2009-04-20 Thread Jani Hakala
Raymond Hettinger writes: > FWIW, I wrote the docs. The pure python forms were put in > as an integral part of the documentation. The first > sentence of prose was not meant to stand alone. It is a > lead-in to the code which makes explicit the short-circuiting > behavior and the behavior when

Re: any(), all() and empty iterable

2009-04-20 Thread Antoon Pardon
On 2009-04-15, John O'Hagan wrote: > On Tue, 14 Apr 2009, Mark Dickinson wrote: >> On Apr 14, 7:21 pm, Luis Alberto Zarrabeitia Gomez >> >> wrote: >> > It's more than that. Python's following the rules here. Maybe it could be >> > documented better, for those without a background in logic/discret

Re: any(), all() and empty iterable

2009-04-16 Thread Roel Schroeven
Dale Roberts schreef: > On Apr 16, 2:27 pm, Tim Chase wrote: >> Raymond Hettinger wrote: >>> I will not change the sentence to "return false if any element >>> of the iterable is false." The negations make the sentence >>> hard to parse mentally >> Just as a ribbing, that "return X if any element

Re: any(), all() and empty iterable

2009-04-16 Thread Luis Zarrabeitia
On Thursday 16 April 2009 02:46:24 pm Dale Roberts wrote: > On Apr 16, 2:27 pm, Tim Chase wrote: > > Yes, I now appreciate the motivation for having the word "all" in the > text, and simply adding something like "or the iterable is empty" > might head off future confusion. /me wonders how no one

Re: any(), all() and empty iterable

2009-04-16 Thread Raymond Hettinger
> Thanks for weighing in, Raymond. You're welcome. > As long as people are getting in their > last licks on this one ... > > Including the word "all" in the definition of "all()" is suboptimal. > Especially since the everyday meaning of "all" is ambiguous. Sure, leave > in the code-equivalent to

Re: any(), all() and empty iterable

2009-04-16 Thread John Posner
Tim Chase wrote: I will probably leave the lead-in sentence as-is but may add another sentence specifically covering the case for an empty iterable. as one of the instigators in this thread, I'm +1 on this solution. Thanks for weighing in, Raymond. As long as people are getting in their last

Re: any(), all() and empty iterable

2009-04-16 Thread Dale Roberts
On Apr 16, 2:27 pm, Tim Chase wrote: > Raymond Hettinger wrote: > > I will not change the sentence to "return false if any element > > of the iterable is false."  The negations make the sentence > > hard to parse mentally > > Just as a ribbing, that "return X if any element of the iterable > is X"

Re: any(), all() and empty iterable

2009-04-16 Thread Paul Rudin
Tim Chase writes: > Changing the implementation of all() would break wy too much > stuff... Not to mention it clearly works correctly as is. *If* there is an issue it is a documentation one... not an implementation one. -- http://mail.python.org/mailman/listinfo/python-list

Re: any(), all() and empty iterable

2009-04-16 Thread Tim Chase
Raymond Hettinger wrote: I will not change the sentence to "return false if any element of the iterable is false." The negations make the sentence hard to parse mentally Just as a ribbing, that "return X if any element of the iterable is X" is of the same form as the original. The negation

Re: any(), all() and empty iterable

2009-04-16 Thread Raymond Hettinger
> The doc should speak to the intended audience: programmers, who like > to make sure all bases and cases are covered. FWIW, I wrote the docs. The pure python forms were put in as an integral part of the documentation. The first sentence of prose was not meant to stand alone. It is a lead-in to

Re: any(), all() and empty iterable

2009-04-16 Thread Dale Roberts
On Apr 14, 8:33 am, Tim Chase wrote: > ... > I still prefer "Return False if any element of the iterable is > not true" or "Return False if any element in the iterable is > false" because that describes exactly what the algorithm does. I agree that the original doc comment is not helpful as it st

Re: any(), all() and empty iterable

2009-04-14 Thread Aaron Brady
On Apr 14, 7:32 pm, John O'Hagan wrote: > On Tue, 14 Apr 2009, Mark Dickinson wrote: > > On Apr 14, 7:21 pm, Luis Alberto Zarrabeitia Gomez > > > wrote: > > > It's more than that. Python's following the rules here. Maybe it could be > > > documented better, for those without a background in logic

Re: any(), all() and empty iterable

2009-04-14 Thread Steven D'Aprano
On Tue, 14 Apr 2009 14:27:59 +0100, Arnaud Delobelle wrote: > In fact the doc is not just misleading, but plain wrong as the following > shows: > def alwaystrue(): > ... while True: yield True > ... all(alwaystrue()) > [Python is stuck] > > The iterable alwaystrue() satisfies the p

Re: any(), all() and empty iterable

2009-04-14 Thread Steven D'Aprano
On Tue, 14 Apr 2009 17:54:14 +, John O'Hagan wrote: > Agreed; having absorbed the answers to my original question, I now > understand why all('Robinson Crusoe' in books for books in []) - or with > any object in place of the string, or indeed just all([]) - doesn't > return False, but, vacuous

Re: any(), all() and empty iterable

2009-04-14 Thread Piet van Oostrum
> Mark Dickinson (MD) wrote: >MD> On Apr 14, 7:21 pm, Luis Alberto Zarrabeitia Gomez >MD> wrote: >>> It's more than that. Python's following the rules here. Maybe it could be >>> documented better, for those without a background in logic/discrete >>> mathematics, >>> but not changed. >MD>

Re: any(), all() and empty iterable

2009-04-14 Thread John O'Hagan
On Tue, 14 Apr 2009, Mark Dickinson wrote: > On Apr 14, 7:21 pm, Luis Alberto Zarrabeitia Gomez > > wrote: > > It's more than that. Python's following the rules here. Maybe it could be > > documented better, for those without a background in logic/discrete > > mathematics, but not changed. > > Agr

Re: any(), all() and empty iterable

2009-04-14 Thread Mark Dickinson
On Apr 14, 7:21 pm, Luis Alberto Zarrabeitia Gomez wrote: > It's more than that. Python's following the rules here. Maybe it could be > documented better, for those without a background in logic/discrete > mathematics, > but not changed. Agreed. I'd like to guess that in 93.7% of cases, when a

Re: any(), all() and empty iterable

2009-04-14 Thread Luis Alberto Zarrabeitia Gomez
Quoting John O'Hagan : > An exception, or at least a specific mention of the case of empty iterables > in the docs (as Tim Chase suggested), would have baffled me less than my > program telling me that the same items were both ubiquitous and entirely > absent from a list of sets! Well, they _w

Re: any(), all() and empty iterable

2009-04-14 Thread John O'Hagan
On Tue, 14 Apr 2009, Carl Banks wrote: > On Apr 12, 10:45 am, Tim Chase wrote: > > > That's why you ask "Do you have any books called 'Robinson Crusoe'?" > > > rather than "Are all your books called 'Robinson Crusoe'?". > > > > Mu.  If I don't have any books..."Have you stopped beating all > > you

Re: any(), all() and empty iterable

2009-04-14 Thread John Posner
Tim Chase wrote: I still prefer "Return False if any element of the iterable is not true" or "Return False if any element in the iterable is false" because that describes exactly what the algorithm does. Granted, anybody with a mote of Python skills can tell that from the algorithm, but if you

Re: any(), all() and empty iterable

2009-04-14 Thread Carl Banks
On Apr 12, 10:45 am, Tim Chase wrote: > > That's why you ask "Do you have any books called 'Robinson Crusoe'?" rather > > than "Are all your books called 'Robinson Crusoe'?". > > Mu.  If I don't have any books..."Have you stopped beating all > your wives?"  The question makes the presumption that

Re: any(), all() and empty iterable

2009-04-14 Thread Arnaud Delobelle
Tim Chase writes: > Peter Pearson wrote: >> On Sun, 12 Apr 2009 06:53:24 -0500, Tim Chase wrote: >From the docs: all(iterable) Return True if all elements of the iterable are true. Equivalent to: def all(iterable):

Re: any(), all() and empty iterable

2009-04-14 Thread Tim Chase
Peter Pearson wrote: On Sun, 12 Apr 2009 06:53:24 -0500, Tim Chase wrote: >From the docs: all(iterable) Return True if all elements of the iterable are true. Equivalent to: def all(iterable): for element in iterable: if not

Re: any(), all() and empty iterable

2009-04-13 Thread Peter Pearson
On Sun, 12 Apr 2009 06:53:24 -0500, Tim Chase wrote: >>>From the docs: >> >> all(iterable) >> >> Return True if all elements of the iterable are true. Equivalent >> to: >> >> def all(iterable): >> for element in iterable: >> if

Re: any(), all() and empty iterable

2009-04-12 Thread Eduardo O. Padoan
On Sun, Apr 12, 2009 at 8:53 AM, Tim Chase wrote: >>> From the docs: >> >> all(iterable) >>                Return True if all elements of the iterable are true. >> Equivalent >>        to: >>                def all(iterable): >>            for element in iterable: >>                if not element:

Re: any(), all() and empty iterable

2009-04-12 Thread Tim Chase
That's why you ask "Do you have any books called 'Robinson Crusoe'?" rather than "Are all your books called 'Robinson Crusoe'?". Mu. If I don't have any books..."Have you stopped beating all your wives?" The question makes the presumption that I have books (or that you've been beating your w

Re: any(), all() and empty iterable

2009-04-12 Thread Peter Otten
John O'Hagan wrote: > Or to put it another way, if I ask someone "Amongst your books, is one of > them 'Robinson Crusoe'?", and they don't have any books, they could > answer 'yes' (or 'no' equally truthfully), but I'd rather they told me > that no, they don't have  'Robinson Crusoe'. That's why

Re: any(), all() and empty iterable

2009-04-12 Thread John O'Hagan
On Sun, 12 Apr 2009, Chris Rebert wrote: > On Sat, Apr 11, 2009 at 9:00 PM, John O'Hagan wrote: > > Hi, > > > > I was getting some surprising false positives as a result of not > > expecting this: > > > > all(element in item for item in iterable) > > > > to return True when 'iterable' is empty. [

Re: any(), all() and empty iterable

2009-04-12 Thread Arnaud Delobelle
Tim Chase writes: > Arnaud Delobelle wrote: >> Paul Rubin writes: >> >>> Tim Chase writes: > Return True if all elements of the iterable are > true. ... Then I'd say the comment is misleading. An empty list has no item that is tru

Re: any(), all() and empty iterable

2009-04-12 Thread John O'Hagan
On Sun, 12 Apr 2009, Paul Rubin wrote: > Tim Chase writes: > > > Return True if all elements of the iterable are > > > true. ... > > > > Then I'd say the comment is misleading. An empty list has no item > > that is true (or false), yet it returns true. > > The comment is correct.

Re: any(), all() and empty iterable

2009-04-12 Thread Arnaud Delobelle
Paul Rubin writes: > Tim Chase writes: >> > Return True if all elements of the iterable are >> > true. ... >> Then I'd say the comment is misleading. An empty list has no item >> that is true (or false), yet it returns true. > > The comment is corr

Re: any(), all() and empty iterable

2009-04-12 Thread Tim Chase
Arnaud Delobelle wrote: Paul Rubin writes: Tim Chase writes: Return True if all elements of the iterable are true. ... Then I'd say the comment is misleading. An empty list has no item that is true (or false), yet it returns true. The comment

Re: any(), all() and empty iterable

2009-04-12 Thread Paul Rubin
Tim Chase writes: > > Return True if all elements of the iterable are > > true. ... > Then I'd say the comment is misleading. An empty list has no item > that is true (or false), yet it returns true. The comment is correct. "All the items of the iterable are true" means EXACTLY

Re: any(), all() and empty iterable

2009-04-12 Thread Tim Chase
From the docs: all(iterable) Return True if all elements of the iterable are true. Equivalent to: def all(iterable): for element in iterable: if not element: return False return True Then I'

Re: any(), all() and empty iterable

2009-04-11 Thread Luis Alberto Zarrabeitia Gomez
Quoting John O'Hagan : > Hi, > > I was getting some surprising false positives as a result of not expecting > this: > > all(element in item for item in iterable) > > to return True when 'iterable' is empty. > [...] > any(element in item for item in iterable) > > which returns False when 'i

Re: any(), all() and empty iterable

2009-04-11 Thread Albert Hopkins
On Sun, 2009-04-12 at 04:00 +, John O'Hagan wrote: > Hi, > > I was getting some surprising false positives as a result of not expecting > this: > > all(element in item for item in iterable) > > to return True when 'iterable' is empty. > > I guess it goes into hairy Boolean territory tryin

Re: any(), all() and empty iterable

2009-04-11 Thread Chris Rebert
On Sat, Apr 11, 2009 at 9:00 PM, John O'Hagan wrote: > Hi, > > I was getting some surprising false positives as a result of not expecting > this: > > all(element in item for item in iterable) > > to return True when 'iterable' is empty. > > I guess it goes into hairy Boolean territory trying to de