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

Jeremy Fincher tweedgeezer at hotmail.com
Wed Nov 27 04:55:03 EST 2002


"John Roth" <johnroth at ameritech.net> wrote in message news:<uu7ogatjhprm9b at news.supernews.com>...
> 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.

What's asymmetric is that filter and map operate over any sequence but
only return lists; if, instead, they had been methods on lists, then
implementations of other container data structures (dictionaries,
binary trees, strings, etc.) could provide their own filter and map
methods that returned values of the same type.

Reduce (which I so wish was called foldl, leaving the oppurtunity open
for a symmetric foldr) is really the only of the three
(map/filter/reduce) that makes sense as a function (rather than as a
method) since it's defined over sequences in general, and sequences
don't by nature make an appearance in its return value.

Jeremy



More information about the Python-list mailing list