[Python-3000] Python 3000 Status Update (Long!)
Nick Coghlan
ncoghlan at gmail.com
Wed Jun 20 12:31:38 CEST 2007
Christian Heimes wrote:
> Bill Janssen wrote:
>> Though, from the standpoint of pragmatism, removing "reduce" from the
>> built-in space will break code (*my* code, among others), and leaving
>> it in will not affect "purity", as both "map" and "reduce" are being
>> left in. So leaving it alone seems the more Pythonic response to me.
>
> Python 3000 tries to reduce (hehe) the amount of builtins so reduce was
> removed since it is rarely used. I don't understand why map and filter
> wasn't moved to functools, too.
Because (str(x) for x in seq) is not an improvement over map(str, x) -
applying a single existing function to a sequence is a very common
operation.
map() accepts any function (given an appropriate number of sequences),
and thus has wide applicability.
filter() accepts any single argument predicate function (using bool() by
default), and thus also has wide applicability.
reduce(), on the other hand, works only with functions that are
specially designed to be fed to it - you are unlikely to have an
appropriate function just lying around. Given the likely need to write a
special function to perform the desired reduction importing the reduce
function itself isn't going to be much additional overhead.
From the point of view of readability, it is probably going to be
better to hide the fact that reduce is being used at all behind a named
reduction function (or, where possible, just use one of the builtin
sequence reduction functions like any(), all(), sum(), min(), max()).
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
More information about the Python-3000
mailing list