[Python-Dev] Adding any() and all()

Brett C. bac at OCF.Berkeley.EDU
Sat Mar 12 07:25:23 CET 2005

Jim Jewett wrote:
> Guido van Rossum:
>>Whether to segregate these into a separate module: they are really a
>>very small amount of syntactic sugat, and I expect that in most cases,
>>instead of importing that module (which totally makes me lose my
>>context while editing) I would probably just write the extra line that
>>it takes to get the same effect with an explicit for loop and if
> Is that so bad?
> If you plan to use them often, then
>     from itertools import any, every
> is reasonable.  If you only use them once and weren't expecting it
> (and want your imports at the top) ... well how awful is it to have 
> an extra line or two in your code?

Basically the question (at least in my mind) when it comes to built-ins is 
whether the usage is so basic and fundamental that sticking them in a module is 
done more for rigid organization than for convenience.  Personally, I think 
any() and all() meet this requirement.  With their ties to basic boolean 
testing they should be built into the language and not just a part of the 
stdlib.  If I am banging something out at a interpreter prompt I will want 
these functions easily accessible and I won't think of them as something to 
import.  This probably comes off as wishy-washy, but it is just what my mind is 
spitting out at the moment.

They also have the feeling as something that could be useful as a syntax 
(although I am just suggesting syntactic support!).  Which could be an even 
better way to measure whether something should be a built-in.  Would the 
function be useful as a syntactic addition to the language, but just can't 
quite reach the need of a new keyword?  Once again any() and all() feel like 
that to me.

> These aren't *really* replacing map/filter/reduce because you're
> adding the new functions now, but the old-function removal is 
> waiting until (forever?)

Even if Python 3000 comes out a while from now, why wait?  Two more is not that 
much.  Besides, it isn't like we are adding functions as some crazy rate.  And 
Guido has stated that the 2.x branch stops once 2.9 (if it goes that long) 
comes out.  So at worst you only have to worry about 5 more releases to worry.  =)


More information about the Python-Dev mailing list