filterout() builtin function 
Author Message
 filterout() builtin function

I sometimes need the inverse of the builtin filter().  If I'm doing
something relatively efficient like filtering for dictionary keys using
has_key, it's rather disappointing to have to write a python function to do
that.  As an alternative, here are diffs to Python/bltinmodule.c that add a
filterout() builtin function.

Skip Montanaro     |  Looking for a place to promote your music venue, new CD,

(518)372-5583      |  ad in Musi-Cal!   http://www.*-*-*.com/
 ----- Support free speech online: http://www.*-*-*.com/

diff -c2 bltinmodule.c~ bltinmodule.c
*** bltinmodule.c~      Fri Aug  4 00:07:45 1995
--- bltinmodule.c       Thu Apr  4 13:40:37 1996
***************
*** 110,116 ****

  static object *
! builtin_filter(self, args)
        object *self;
        object *args;
  {
        object *func, *seq, *result;
--- 110,117 ----

  static object *
! builtin_filter_helper(self, args, flag)
        object *self;
        object *args;
+       int flag;
  {
        object *func, *seq, *result;
***************
*** 181,185 ****
                ok = testbool(good);
                DECREF(good);
!               if (ok) {
                        if (j < len) {
                                if (setlistitem(result, j++, item) < 0)
--- 182,186 ----
                ok = testbool(good);
                DECREF(good);
!               if (ok && flag || !(ok || flag)) {
                        if (j < len) {
                                if (setlistitem(result, j++, item) < 0)
***************
*** 209,212 ****
--- 210,229 ----

  static object *
+ builtin_filter(self, args)
+       object *self;
+       object *args;
+ {
+       return builtin_filter_helper(self, args, 1);
+ }
+
+ static object *
+ builtin_filter_out(self, args)
+       object *self;
+       object *args;
+ {
+       return builtin_filter_helper(self, args, 0);
+ }
+
+ static object *
  builtin_chr(self, args)
        object *self;
***************
*** 1401,1404 ****
--- 1418,1422 ----
        {"execfile",    builtin_execfile, 1},
        {"filter",      builtin_filter, 1},
+       {"filterout",   builtin_filter_out, 1},
        {"float",       builtin_float, 1},
        {"getattr",     builtin_getattr, 1},



Mon, 21 Sep 1998 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Builtin methods versus Builtin Functions -- help!

2. Pickler that handles modules, functions, and builtin functions -- done

3. generic functions to redefine builtin functions - how ?

4. DECIMAL Builtin Function

5. Regina vs IBM REXX: builtin functions

6. How to get the Callable of builtin functions

7. builtin functions

8. i need help on builtin function math

9. why is open() a builtin function?

10. Name od builtin functions: is there a rule ??

11. Explicit call of builtin functions

12. determining identity of a builtin C function

 

 
Powered by phpBB® Forum Software