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

Jim Jewett jimjjewett at gmail.com
Fri Mar 11 20:29:51 CET 2005


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

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?

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?)

A compromise (which may not be worth doing) would be to put
them in another module, and then import them into  __builtins__
if desired.  map/filter/reduce could be moved out (but reimported
for at least 2.5) in the same way, which would make their 
inclusion look more like "standard policy" than "part of the 
language".

[And yes, I know that itertools might be the "wrong" module; I 
just don't remember the name of the module for iteration-related 
tools that happen to return something other than an iterator.]

-jJ


More information about the Python-Dev mailing list