Python Tutorial Was: Guido's regrets: filter and map

Jp Calderone exarkun at meson.dyndns.org
Tue Nov 26 17:49:14 EST 2002


On Tue, Nov 26, 2002 at 04:05:27PM -0500, John Roth wrote:
> 
> Well, both filter and map are defined only for lists, so list
> comprehensions don't provide a reduction of function there. Reduce is
> defined for sequences.

>>> def notAList(x):
...     while x:
...         yield x
...         x -= 1
... 
>>> map((2).__mul__, notAList(10))
[20, 18, 16, 14, 12, 10, 8, 6, 4, 2]
>>> 

  Hmmm.  The return type is always a list, sure.  The input need only be
iterable.

> 
> I could see filter and reduce as methods. Since map is a function across
> a number of input lists, I have a somewhat harder time seeing it that
> way - it looks a bit assymetric to me.

  map *might* make sense as a function method (oy) but then, since Python
has more than one type of callable, that wouldn't be too hot either.  I
don't think I'd like seeing any of the three defined this way though.

  Jp

-- 
C/C++/Java/Perl/Python/Smalltalk/PHP/ASP/XML/Linux (User+Admin)
Genetic Algorithms/Genetic Programming/Neural Networks
Networking/Multithreading/Legacy Code Maintenance/OpenGL
See my complete resume at http://intarweb.us:8080/
--
 12:00am up 24 days, 10:54, 7 users, load average: 1.89, 1.23, 0.80
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20021126/e2a5a363/attachment.sig>


More information about the Python-list mailing list