[Python-3000] Python 3000 Status Update (Long!)

Mike Klaas mike.klaas at gmail.com
Tue Jun 19 20:19:09 CEST 2007


On 19-Jun-07, at 10:51 AM, 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.

map (especially the new iterized version) is a frequently-used  
builtin, while reduce is a rarely-used builtin that requires some  
head-wrapping.  It makes sense to me to move it out of builtins.

To pick a codebase at random (mine):

$ find -name \*.py | xargs wc -l
  137952 total

$ pygrep map\( | wc -l
220

$ pygrep imap\( | wc -l
13

$ pygrep reduce\( | wc -l
2

Of the two uses of reduce(), one is in a unittest that should be  
using any():

         self.assertTrue(not reduce((lambda b1, b2: b1 or b2), ...

and the other is a tricky combination of callable "iterator filters"  
that looks something like this:

         df = lambda itr: reduce(lambda x, f: f(x), filter_list, itr)

this isn't the clearest piece of code, even with more explanation.   
It would require a multi-line inner-function generator to replace  
it.  I'm have no qualms importing reduce for such uses.

In contrast, partial(), which should have less use as most of the  
codebase was written pre-2.5, and requires an import, is used four  
times:

$ pygrep partial\( | wc -l
4

-Mike



More information about the Python-3000 mailing list