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

Brian Quinlan brian at sweetapp.com
Wed Nov 27 14:03:17 EST 2002


Jeremy Fincher wrote:
> Since they operate on any sequence, they should be methods of any
> sequence.  As functions, yes, they operate on all sequences, but they
> only return lists. 

It would be trivial to write type specific map/filter functions yourself
e.g.

def tuple_map(*args, **kwargs): return tuple(map(*args, **kwargs)

> As methods, map/filter would return sequences of
> the same type they operated on, which is (IMO) far more appropriate.

Should iterators have a map/filter method? Would they return another
iterator?

> In short, why should a map on a string return a list instead of a
> string?  

I see no reason why it wouldn't. 

> Why should a filter on a binary tree return a list instead of
> another binary tree?

You lost me on this one. What builtin type is your binary tree? Or are
you supposing that binary tree become a builtin?

Cheers,
Brian





More information about the Python-list mailing list