我们从Python开源项目中,提取了以下39个代码示例,用于说明如何使用six.moves.filterfalse()。
def _unique_everseen(iterable, key=None): "List unique elements, preserving order. Remember all elements ever seen." # unique_everseen('AAAABBBCCDAABBB') --> A B C D # unique_everseen('ABBCcAD', str.lower) --> A B C D seen = set() seen_add = seen.add if key is None: for element in filterfalse(seen.__contains__, iterable): seen_add(element) yield element else: for element in iterable: k = key(element) if k not in seen: seen_add(k) yield element
def _unique_everseen(self, iterable, key=None): """ List unique elements, preserving order. Remember all elements ever seen. _unique_everseen('AAAABBBCCDAABBB') --> A B C D _unique_everseen('ABBCcAD', str.lower) --> A B C D """ seen = set() seen_add = seen.add if key is None: for element in filterfalse(seen.__contains__, iterable): seen_add(element) yield element else: for element in iterable: k = key(element) if k not in seen: seen_add(k) yield element
def partition(iterable, pred): """ Split iterable into two partitions based on predicate function >>> pred = lambda x: x < 6 >>> smaller, larger = partition(range(10), pred) >>> list(smaller) [0, 1, 2, 3, 4, 5] >>> list(larger) [6, 7, 8, 9] :param iterable: Any iterable, e.g. list, range, ... :param pred: Predicate function. :return: Partition iterators :rtype: Two iterators """ t1, t2 = itt.tee(iterable) return filter(pred, t1), filterfalse(pred, t2)
def partition(pred, iterable): """ Partition the iterable into two disjoint entries based on the predicate. @return: Tuple (iterable1, iterable2) """ iter1, iter2 = itertools.tee(iterable) return filterfalse(pred, iter1), filter(pred, iter2)
def test_filter_false(): from six.moves import filterfalse f = filterfalse(lambda x: x % 3, range(10)) assert six.advance_iterator(f) == 0 assert six.advance_iterator(f) == 3 assert six.advance_iterator(f) == 6