[Python-Dev] Adding any() and all()
python at rcn.com
Fri Mar 11 18:18:17 CET 2005
> BTW I definitely expect having to defend removing
> map/filter/reduce/lambda with a PEP; that's much more controversial
> because it's *removing* something and hence by definition breaking
I suspect that lambda will be the only bone of contention. The reduce()
function can be moved to the functional module. The map() and filter()
functions are already covered by the itertools module.
Lambda will be more difficult. Eric Raymond adapted an anti-gun control
slogan and said "you can pry lambda out of my cold dead hands." A bunch
of folks will sorely miss the ability to create anonymous functions on
the fly. When lambda is used for deferred argument evaluation (a la PEP
312), the def syntax is a crummy substitute.
> PS in the blog responses, a problem with sum() was pointed out --
> unless you use the second argument, it will only work for numbers. Now
> that string concatenation is apparently O(N) rather than O(N**2) (is
> that right, Raymond?) maybe this could be revised.
str.join() is still the best practice for string concatenation.
Armin's optimization doesn't appear in other implementations of Python.
In CPython, it has a set of pre-conditions that are usually but not
always True. IIRC, it also doesn't apply to Unicode and ASCII mixed
Also, the optimization is part of ceval.c and would not be triggered by
sum()'s call to PyNumber_Add(). That limitation is not easily removed
because the optimization depends on an interaction between the stack,
variable refcounts, and the sequence of opcodes.
IOW, your original pronouncement on the subject should remain in effect.
More information about the Python-Dev