我们从Python开源项目中,提取了以下24个代码示例,用于说明如何使用__builtin__.filter()。
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/
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
def lfilter(*args, **kwargs): return list(filter(*args, **kwargs))