Python builtins.filter() Examples

The following are 30 code examples of builtins.filter(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module builtins , or try the search function .
Example #1
Source File: noniterators.py    From misp42splunk with GNU Lesser General Public License v3.0 6 votes vote down vote up
def oldfilter(*args):
        """
        filter(function or None, sequence) -> list, tuple, or string

        Return those items of sequence for which function(item) is true.
        If function is None, return the items that are true.  If sequence
        is a tuple or string, return the same type, else return a list.
        """
        mytype = type(args[1])
        if isinstance(args[1], basestring):
            return mytype().join(builtins.filter(*args))
        elif isinstance(args[1], (tuple, list)):
            return mytype(builtins.filter(*args))
        else:
            # Fall back to list. Is this the right thing to do?
            return list(builtins.filter(*args))

    # This is surprisingly difficult to get right. For example, the
    # solutions here fail with the test cases in the docstring below:
    # http://stackoverflow.com/questions/8072755/ 
Example #2
Source File: noniterators.py    From kgsgo-dataset-preprocessor with Mozilla Public License 2.0 6 votes vote down vote up
def oldfilter(*args):
        """
        filter(function or None, sequence) -> list, tuple, or string
        
        Return those items of sequence for which function(item) is true.
        If function is None, return the items that are true.  If sequence
        is a tuple or string, return the same type, else return a list.
        """
        mytype = type(args[1])
        if isinstance(args[1], basestring):
            return mytype().join(builtins.filter(*args))
        elif isinstance(args[1], (tuple, list)):
            return mytype(builtins.filter(*args))
        else:
            # Fall back to list. Is this the right thing to do?
            return list(builtins.filter(*args))

    # This is surprisingly difficult to get right. For example, the
    # solutions here fail with the test cases in the docstring below:
    # http://stackoverflow.com/questions/8072755/ 
Example #3
Source File: pandas_py3k.py    From kgsgo-dataset-preprocessor with Mozilla Public License 2.0 6 votes vote down vote up
def __and__(self, other):
        ''' Intersection is the minimum of corresponding counts.

        >>> Counter('abbb') & Counter('bcc')
        Counter({'b': 1})

        '''
        if not isinstance(other, Counter):
            return NotImplemented
        _min = min
        result = Counter()
        if len(self) < len(other):
            self, other = other, self
        for elem in filter(self.__contains__, other):
            newcount = _min(self[elem], other[elem])
            if newcount > 0:
                result[elem] = newcount
        return result 
Example #4
Source File: noniterators.py    From deepWordBug with Apache License 2.0 6 votes vote down vote up
def oldfilter(*args):
        """
        filter(function or None, sequence) -> list, tuple, or string
        
        Return those items of sequence for which function(item) is true.
        If function is None, return the items that are true.  If sequence
        is a tuple or string, return the same type, else return a list.
        """
        mytype = type(args[1])
        if isinstance(args[1], basestring):
            return mytype().join(builtins.filter(*args))
        elif isinstance(args[1], (tuple, list)):
            return mytype(builtins.filter(*args))
        else:
            # Fall back to list. Is this the right thing to do?
            return list(builtins.filter(*args))

    # This is surprisingly difficult to get right. For example, the
    # solutions here fail with the test cases in the docstring below:
    # http://stackoverflow.com/questions/8072755/ 
Example #5
Source File: __init__.py    From Computable with MIT License 6 votes vote down vote up
def __and__(self, other):
        """Intersection is the minimum of corresponding counts.

        >>> Counter('abbb') & Counter('bcc')
        Counter({'b': 1})

        """
        if not isinstance(other, Counter):
            return NotImplemented
        _min = min
        result = Counter()
        if len(self) < len(other):
            self, other = other, self
        for elem in filter(self.__contains__, other):
            newcount = _min(self[elem], other[elem])
            if newcount > 0:
                result[elem] = newcount
        return result 
Example #6
Source File: noniterators.py    From addon with GNU General Public License v3.0 6 votes vote down vote up
def oldfilter(*args):
        """
        filter(function or None, sequence) -> list, tuple, or string

        Return those items of sequence for which function(item) is true.
        If function is None, return the items that are true.  If sequence
        is a tuple or string, return the same type, else return a list.
        """
        mytype = type(args[1])
        if isinstance(args[1], basestring):
            return mytype().join(builtins.filter(*args))
        elif isinstance(args[1], (tuple, list)):
            return mytype(builtins.filter(*args))
        else:
            # Fall back to list. Is this the right thing to do?
            return list(builtins.filter(*args))

    # This is surprisingly difficult to get right. For example, the
    # solutions here fail with the test cases in the docstring below:
    # http://stackoverflow.com/questions/8072755/ 
Example #7
Source File: noniterators.py    From telegram-robot-rss with Mozilla Public License 2.0 6 votes vote down vote up
def oldfilter(*args):
        """
        filter(function or None, sequence) -> list, tuple, or string
        
        Return those items of sequence for which function(item) is true.
        If function is None, return the items that are true.  If sequence
        is a tuple or string, return the same type, else return a list.
        """
        mytype = type(args[1])
        if isinstance(args[1], basestring):
            return mytype().join(builtins.filter(*args))
        elif isinstance(args[1], (tuple, list)):
            return mytype(builtins.filter(*args))
        else:
            # Fall back to list. Is this the right thing to do?
            return list(builtins.filter(*args))

    # This is surprisingly difficult to get right. For example, the
    # solutions here fail with the test cases in the docstring below:
    # http://stackoverflow.com/questions/8072755/ 
Example #8
Source File: noniterators.py    From gimp-plugin-export-layers with GNU General Public License v3.0 6 votes vote down vote up
def oldfilter(*args):
        """
        filter(function or None, sequence) -> list, tuple, or string
        
        Return those items of sequence for which function(item) is true.
        If function is None, return the items that are true.  If sequence
        is a tuple or string, return the same type, else return a list.
        """
        mytype = type(args[1])
        if isinstance(args[1], basestring):
            return mytype().join(builtins.filter(*args))
        elif isinstance(args[1], (tuple, list)):
            return mytype(builtins.filter(*args))
        else:
            # Fall back to list. Is this the right thing to do?
            return list(builtins.filter(*args))

    # This is surprisingly difficult to get right. For example, the
    # solutions here fail with the test cases in the docstring below:
    # http://stackoverflow.com/questions/8072755/ 
Example #9
Source File: controllerlib.py    From aerospike-admin with Apache License 2.0 6 votes vote down vote up
def _init_commands(self):
        command_re = re.compile("^(do_(.*))$")
        commands = [command_re.match(v).groups() for v in list(filter(command_re.search, dir(self)))]

        self.commands = PrefixDict()

        for command in commands:
            self.commands.add(command[1], getattr(self, command[0]))

        for command, controller in list(self.controller_map.items()):
            try:
                controller = controller()
            except Exception:
                pass

            self.commands.add(command, controller) 
Example #10
Source File: noniterators.py    From arissploit with GNU General Public License v3.0 6 votes vote down vote up
def oldfilter(*args):
        """
        filter(function or None, sequence) -> list, tuple, or string
        
        Return those items of sequence for which function(item) is true.
        If function is None, return the items that are true.  If sequence
        is a tuple or string, return the same type, else return a list.
        """
        mytype = type(args[1])
        if isinstance(args[1], basestring):
            return mytype().join(builtins.filter(*args))
        elif isinstance(args[1], (tuple, list)):
            return mytype(builtins.filter(*args))
        else:
            # Fall back to list. Is this the right thing to do?
            return list(builtins.filter(*args))

    # This is surprisingly difficult to get right. For example, the
    # solutions here fail with the test cases in the docstring below:
    # http://stackoverflow.com/questions/8072755/ 
Example #11
Source File: noniterators.py    From Tautulli with GNU General Public License v3.0 6 votes vote down vote up
def oldfilter(*args):
        """
        filter(function or None, sequence) -> list, tuple, or string

        Return those items of sequence for which function(item) is true.
        If function is None, return the items that are true.  If sequence
        is a tuple or string, return the same type, else return a list.
        """
        mytype = type(args[1])
        if isinstance(args[1], basestring):
            return mytype().join(builtins.filter(*args))
        elif isinstance(args[1], (tuple, list)):
            return mytype(builtins.filter(*args))
        else:
            # Fall back to list. Is this the right thing to do?
            return list(builtins.filter(*args))

    # This is surprisingly difficult to get right. For example, the
    # solutions here fail with the test cases in the docstring below:
    # http://stackoverflow.com/questions/8072755/ 
Example #12
Source File: noniterators.py    From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International 6 votes vote down vote up
def oldfilter(*args):
        """
        filter(function or None, sequence) -> list, tuple, or string

        Return those items of sequence for which function(item) is true.
        If function is None, return the items that are true.  If sequence
        is a tuple or string, return the same type, else return a list.
        """
        mytype = type(args[1])
        if isinstance(args[1], basestring):
            return mytype().join(builtins.filter(*args))
        elif isinstance(args[1], (tuple, list)):
            return mytype(builtins.filter(*args))
        else:
            # Fall back to list. Is this the right thing to do?
            return list(builtins.filter(*args))

    # This is surprisingly difficult to get right. For example, the
    # solutions here fail with the test cases in the docstring below:
    # http://stackoverflow.com/questions/8072755/ 
Example #13
Source File: tree.py    From helo_word with Apache License 2.0 6 votes vote down vote up
def anchor_id(self):
        """ Yields the anchor tag as parsed from the original token.
            Chunks that are anchors have a tag with an "A" prefix (e.g., "A1").
            Chunks that are PNP attachmens (or chunks inside a PNP) have "P" (e.g., "P1").
            Chunks inside a PNP can be both anchor and attachment (e.g., "P1-A2"),
            as in: "clawed/A1 at/P1 mice/P1-A2 in/P2 the/P2 wall/P2"
        """
        id = ""
        f = lambda ch: list(filter(lambda k: self.sentence._anchors[k] == ch, self.sentence._anchors))
        if self.pnp and self.pnp.anchor:
            id += "-" + "-".join(f(self.pnp))
        if self.anchor:
            id += "-" + "-".join(f(self))
        if self.attachments:
            id += "-" + "-".join(f(self))
        return id.strip("-") or None 
Example #14
Source File: noniterators.py    From misp42splunk with GNU Lesser General Public License v3.0 6 votes vote down vote up
def oldfilter(*args):
        """
        filter(function or None, sequence) -> list, tuple, or string

        Return those items of sequence for which function(item) is true.
        If function is None, return the items that are true.  If sequence
        is a tuple or string, return the same type, else return a list.
        """
        mytype = type(args[1])
        if isinstance(args[1], basestring):
            return mytype().join(builtins.filter(*args))
        elif isinstance(args[1], (tuple, list)):
            return mytype(builtins.filter(*args))
        else:
            # Fall back to list. Is this the right thing to do?
            return list(builtins.filter(*args))

    # This is surprisingly difficult to get right. For example, the
    # solutions here fail with the test cases in the docstring below:
    # http://stackoverflow.com/questions/8072755/ 
Example #15
Source File: GdalTools_utils.py    From WMF with GNU General Public License v3.0 5 votes vote down vote up
def allRastersFilter(self):
        if self.rastersFilter == '':
            self.rastersFilter = QgsProviderRegistry.instance().fileRasterFilters()

            # workaround for QGis < 1.5 (see #2376)
            # removed as this is a core plugin QGis >= 1.9

        return self.rastersFilter

    # Retrieves the last used filter for raster files
    # Note: filter string is in a list 
Example #16
Source File: GdalTools_utils.py    From WMF with GNU General Public License v3.0 5 votes vote down vote up
def allVectorsFilter(self):
        if self.vectorsFilter == '':
            self.vectorsFilter = QgsProviderRegistry.instance().fileVectorFilters()
        return self.vectorsFilter

    # Retrieves the last used filter for vector files
    # Note: filter string is in a list 
Example #17
Source File: GdalTools_utils.py    From WMF with GNU General Public License v3.0 5 votes vote down vote up
def setLastUsedVectorFilter(self, aFilter):
        self.setFilter("lastVector", aFilter[0])

    # Retrieves the extensions list from a filter string 
Example #18
Source File: GdalTools_utils.py    From WMF with GNU General Public License v3.0 5 votes vote down vote up
def getFilterExtensions(self, aFilter):
        extList = []
        # foreach format in filter string
        for f in aFilter.split(";;"):
            # gets the list of extensions from the filter
            exts = re.sub('\).*$', '', re.sub('^.*\(', '', f))
            # if there is no extensions or the filter matches all, then return an empty list
            # otherwise return the list of estensions
            if exts != '' and exts != "*" and exts != "*.*":
                extList.extend(exts.split(" "))
        return extList 
Example #19
Source File: __coconut__.py    From pyprover with Apache License 2.0 5 votes vote down vote up
def __new__(cls, function, iterable):
        new_filter = _coconut.filter.__new__(cls, function, iterable)
        new_filter.func = function
        new_filter.iter = iterable
        return new_filter 
Example #20
Source File: __init__.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def lfilter(*args, **kwargs):
        return list(filter(*args, **kwargs)) 
Example #21
Source File: __coconut__.py    From pyprover with Apache License 2.0 5 votes vote down vote up
def __repr__(self):
        return "filter(%r, %r)" % (self.func, self.iter) 
Example #22
Source File: GdalTools_utils.py    From WMF with GNU General Public License v3.0 5 votes vote down vote up
def getSaveFileName(self, parent=None, caption='', filter='', selectedFilter=None, useEncoding=False):
        return self.getDialog(parent, caption, QFileDialog.AcceptSave, QFileDialog.AnyFile, filter, selectedFilter,
                              useEncoding) 
Example #23
Source File: setup.py    From pyprover with Apache License 2.0 5 votes vote down vote up
def __new__(cls, function, iterable):
        new_filter = _coconut.filter.__new__(cls, function, iterable)
        new_filter.func = function
        new_filter.iter = iterable
        return new_filter 
Example #24
Source File: setup.py    From pyprover with Apache License 2.0 5 votes vote down vote up
def __repr__(self):
        return "filter(%r, %r)" % (self.func, self.iter) 
Example #25
Source File: sanity.py    From reframe with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def filter(function, iterable):
    '''Replacement for the built-in
    :func:`filter() <python:filter>` function.'''
    return builtins.filter(function, iterable) 
Example #26
Source File: python.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def lfilter(*args, **kwargs):
        return list(filter(*args, **kwargs)) 
Example #27
Source File: __init__.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def lfilter(*args, **kwargs):
        return list(filter(*args, **kwargs)) 
Example #28
Source File: iam_policy_test.py    From forseti-security with Apache License 2.0 5 votes vote down vote up
def _get_member_list(members):
    return [':'.join(filter((lambda x: x is not None),
                            [member.type, member.name]))
            for member in members] 
Example #29
Source File: __init__.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def lfilter(*args, **kwargs):
        return list(filter(*args, **kwargs)) 
Example #30
Source File: __init__.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def lfilter(*args, **kwargs):
        return list(filter(*args, **kwargs))