Python builtins 模块,filter() 实例源码

我们从Python开源项目中,提取了以下20个代码示例,用于说明如何使用builtins.filter()

项目:hakkuframework    作者:4shadoww    | 项目源码 | 文件源码
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/
项目:packaging    作者:blockstack    | 项目源码 | 文件源码
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
项目:packaging    作者:blockstack    | 项目源码 | 文件源码
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/
项目:islam-buddy    作者:hamir    | 项目源码 | 文件源码
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/
项目:FightstickDisplay    作者:calexil    | 项目源码 | 文件源码
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/
项目:cryptogram    作者:xinmingzhang    | 项目源码 | 文件源码
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/
项目:Repobot    作者:Desgard    | 项目源码 | 文件源码
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/
项目:UMOG    作者:hsab    | 项目源码 | 文件源码
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/
项目:beepboop    作者:nicolehe    | 项目源码 | 文件源码
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/
项目:hackathon    作者:vertica    | 项目源码 | 文件源码
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/
项目:yatta_reader    作者:sound88    | 项目源码 | 文件源码
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/
项目:dsbox-profiling    作者:usc-isi-i2    | 项目源码 | 文件源码
def compute_common_numeric_tokens(column, feature, k):
    """
    compute top k frequent numerical tokens and their counts.
    tokens are integer or floats
    e.g. "123", "12.3"
    """
    col = column.str.split(expand=True).unstack().dropna().values
    token = np.array(list(filter(lambda x: hf.is_Decimal_Number(x), col)))
    if token.size:
        feature["frequent-entries"]["most_common_numeric_tokens"] = ordered_dict2(token, k)
项目:dsbox-profiling    作者:usc-isi-i2    | 项目源码 | 文件源码
def compute_common_alphanumeric_tokens(column, feature, k):
    """
    compute top k frequent alphanumerical tokens and their counts.
    tokens only contain alphabets and/or numbers, decimals with points not included
    """
    col = column.str.split(expand=True).unstack().dropna().values
    token = np.array(list(filter(lambda x: x.isalnum(), col)))
    if token.size:
        feature["frequent-entries"]["most_common_alphanumeric_tokens"] = ordered_dict2(token, k)
项目:ngraph    作者:NervanaSystems    | 项目源码 | 文件源码
def gen_conv_testcase():
    """
    Generate convolution test cases

    Returns:
        Iterator of (C, D, H, W, N, T, R, S, K, strides, padding)
    """

    def args_filter(args):
        """
        Filter currently not supported case (only symmetric padding allowed).

        Returns:
            True if args shall be kept.
        """
        C, D, H, W, N, T, R, S, K, strides, padding = args
        pad_t, pad_b, pad_l, pad_r = common_conv2d_pool_padding((N, H, W, C),
                                                                (R, S, C, K),
                                                                strides, padding)
        return pad_t == pad_b and pad_l == pad_r

    # test params
    Cs = [2, ]
    Ds = [1, ]
    Hs = [28, 11]
    Ws = [28, 11]
    Ns = [8, ]
    Ts = [1, ]
    Rs = [1, 3]
    Ss = [1, 3]
    Ks = [4, ]
    strides_list = [[1, 1, 1, 1], [1, 2, 3, 1]]
    paddings = ['SAME', 'VALID']
    all_args = list(
        itertools.product(Cs, Ds, Hs, Ws, Ns, Ts, Rs, Ss, Ks, strides_list,
                          paddings))
    return filter(args_filter, all_args)
项目:ngraph    作者:NervanaSystems    | 项目源码 | 文件源码
def gen_pool_testcase():
    """
    Generate pooling test cases

    Returns:
        Iterator of (C, D, H, W, N, J, T, R, S, strides, padding)
    """

    def args_filter(args):
        """
        Filter currently not supported case (only symmetric padding allowed).

        Returns:
            True if args shall be kept.
        """
        C, D, H, W, N, J, T, R, S, strides, padding = args
        pad_t, pad_b, pad_l, pad_r = common_conv2d_pool_padding((N, H, W, C),
                                                                (R, S, C, C),
                                                                strides, padding)
        return pad_t == pad_b and pad_l == pad_r

    # test params
    Cs = [2, ]
    Ds = [1, ]
    Hs = [28, 11]
    Ws = [28, 11]
    Ns = [8, ]
    Js = [1, ]
    Ts = [1, ]
    Rs = [1, 3]
    Ss = [1, 3]
    strides_list = [[1, 1, 1, 1], [1, 2, 3, 1]]
    paddings = ['SAME', 'VALID']
    all_args = list(
        itertools.product(Cs, Ds, Hs, Ws, Ns, Js, Ts, Rs, Ss, strides_list,
                          paddings))
    return filter(args_filter, all_args)
项目:docximport-sigil-plugin    作者:dougmassay    | 项目源码 | 文件源码
def filter(*args, **kwargs):
        return list(builtins.filter(*args, **kwargs))
项目:packaging    作者:blockstack    | 项目源码 | 文件源码
def lfilter(*args, **kwargs):
        return list(filter(*args, **kwargs))
项目:packaging    作者:blockstack    | 项目源码 | 文件源码
def test_import_builtins(self):
        before = """
        a = raw_input()
        b = open(a, b, c)
        c = filter(a, b)
        d = map(a, b)
        e = isinstance(a, str)
        f = bytes(a, encoding='utf-8')
        for g in xrange(10**10):
            pass
        h = reduce(lambda x, y: x+y, [1, 2, 3, 4, 5])
        super(MyClass, self)
        """
        after = """
        from builtins import bytes
        from builtins import filter
        from builtins import input
        from builtins import map
        from builtins import range
        from functools import reduce
        a = input()
        b = open(a, b, c)
        c = list(filter(a, b))
        d = list(map(a, b))
        e = isinstance(a, str)
        f = bytes(a, encoding='utf-8')
        for g in range(10**10):
            pass
        h = reduce(lambda x, y: x+y, [1, 2, 3, 4, 5])
        super(MyClass, self)
        """
        self.convert_check(before, after, ignore_imports=False, run=False)
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda    作者:SignalMedia    | 项目源码 | 文件源码
def lfilter(*args, **kwargs):
        return list(filter(*args, **kwargs))
项目:reframe    作者:eth-cscs    | 项目源码 | 文件源码
def filter(function, iterable):
    """Replacement for the built-in
    :func:`filter() <python:filter>` function."""
    return builtins.filter(function, iterable)