Python Tutorial Was: Guido's regrets: filter and map
Erik Max Francis
max at alcyone.com
Tue Nov 26 19:13:21 EST 2002
Jeremy Fincher wrote:
> The biggest problem with filter, map, and reduce is that they're
> functions, not methods.
But since they can operate on _any_ sequence, this makes the most sense.
> All this discussion about list comprehensions
> versus filter/map ignores one major disadvantage of list
> comprehensions: that they only work with lists. If filter/map/reduce
> had been *methods* on list objects, then a programmer could implement
> his own container objects (binary trees, subclasses of list, etc.)
But there are several other things that can act as sequence objects,
such as strings, tuples, or user-defined types that don't derive from
list but define a __getitem__ method. filter, map, and reduce really do
belong in the realm of standalone functions, not methods, because they
can apply to any type that _acts_ as a list, whether or not it is a
list, a builtin sequence, or even something which at first sight doesn't
appear to be a sequence type at all (but acts the part).
--
Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/ \ Everyone wants to look good at his own funeral.
\__/ Louis Wu
PyUID / http://www.alcyone.com/pyos/uid/
A module for generating "unique" IDs in Python.
More information about the Python-list
mailing list