[Patches] [ python-Patches-761104 ] adding BaseSet.filter and Set.filter_update

SourceForge.net noreply@sourceforge.net
Thu, 26 Jun 2003 11:45:01 -0700


Patches item #761104, was opened at 2003-06-26 05:15
Message generated for change (Comment added) made by rhettinger
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=761104&group_id=5470

Category: Library (Lib)
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Gerrit Holl (gerrit)
Assigned to: Nobody/Anonymous (nobody)
Summary: adding BaseSet.filter and Set.filter_update

Initial Comment:
Hi,

as proposed in [0], this patch adds a method 'filter'
to BaseSet and a method 'filter_update' to Set. I often
see myself doing "newset = sets.Set(filter(f,
someset))" or "someset = sets.Set(filter(f, someset))".
This is now no longer necessary. I think this method is
a good solution to this problem.

I'm not sure whether it is correct to add my name to
the code history since it is a small change. If this is
not correct feel free to remove it.

This patch also corrects the docstring: the docstring
says _TemporarilyImmutableSet is not a subset of
BaseSet, but it is.

Gerrit.

[0]
http://groups.google.nl/groups?dq=&hl=nl&lr=&ie=UTF-8&oe=UTF-8&group=comp.lang.python&selm=mailman.1056577245.15021.python-list%40python.org


----------------------------------------------------------------------

>Comment By: Raymond Hettinger (rhettinger)
Date: 2003-06-26 13:45

Message:
Logged In: YES 
user_id=80475

* I don't think this should be added to the API.  filter() is a 
builtin because it can be used with many datatypes as an 
input.  Most container contructors have a list format that is 
suitable for use with filter.  It is not unduly burdensome to 
write:  newset=Set(filter(f, oldset)).  The existing approach 
is also more flexible because the user can opt for a list 
comprehension, itertools.ifilter, itertools.ifilterfalse, or any 
other suitable expression.

* If this ends up getting accepted, consider using itertools 
and a simpler, factored implementation:

    def filter(self, f):
        return Set(ifilter(f, self._data))

* Also, a documentation patch and news item would be 
needed.

* I agree with docstring patch and will apply just that piece.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=761104&group_id=5470