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

Terry Reedy tjreedy at udel.edu
Wed Nov 27 12:50:56 EST 2002


"Jeremy Fincher" <tweedgeezer at hotmail.com> wrote in message
news:698f09f8.0211270143.5a3b9f0f at posting.google.com...
> But I think it would be more appropriate for map/filter to return
> sequences of the same type as their argument sequences, not just
> return lists blindly.  And that requires that map/filter be methods,
> not functions over sequences.

There is some sense to this, but:

1. Does not apply to reduce, which produces summary that depends on
type of contents, not container.

2. When map and filter were added with reduce, strings and tuples did
not have methods.  Now that they do, we can, I believe, derive a
subtype with added methods.

3. One can easily convert list output to desired sequence type by
feeding it back through the constructor of the desired type.  String
and tuple constructors need a sequence of fixed length.  Thus,
tuple.filter(f), for instance, would have to scan the tuple twice
anyway.

4. tuple(filter(f,seq)) is much more general than tuple.filter(f).

5. Map can be a function of multiple sequences (iterables), possibly
of multiple types, including generators.  It is then not sensibly a
method of any one.

Terry J. Reedy








More information about the Python-list mailing list