any() and all() on empty list?

Steve R. Hastings steve at hastings.org
Sat Apr 1 01:22:14 EST 2006


On Fri, 31 Mar 2006 16:29:00 -0800, Paul Rubin wrote:
> I think "S and all(S)" is the right way to express that, if that's
> what's intended.

I still would like a standard function, because "S and all(S)" does not
work with iterators.  I proposed one possible function, truecount(S), that
returns a tuple of how many were true and how many there were total.  Then
you could do

true_count, count = truecount(S)

if count and true_count == count:
  # nonempty list and all are true


And S could be an iterator or generator function expression.

You can easily write your own truecount() but it would be nice to have
something like that as standard.  I don't much like the name "truecount"
though; I'm open to suggestions for a better name.
-- 
Steve R. Hastings    "Vita est"
steve at hastings.org    http://www.blarg.net/~steveha




More information about the Python-list mailing list