當前位置: 首頁>>代碼示例>>Python>>正文


Python moves.filterfalse方法代碼示例

本文整理匯總了Python中six.moves.filterfalse方法的典型用法代碼示例。如果您正苦於以下問題:Python moves.filterfalse方法的具體用法?Python moves.filterfalse怎麽用?Python moves.filterfalse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在six.moves的用法示例。


在下文中一共展示了moves.filterfalse方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _unique_everseen

# 需要導入模塊: from six import moves [as 別名]
# 或者: from six.moves import filterfalse [as 別名]
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 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:18,代碼來源:build_py.py

示例2: _unique_everseen

# 需要導入模塊: from six import moves [as 別名]
# 或者: from six.moves import filterfalse [as 別名]
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 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:23,代碼來源:msvc.py

示例3: partition

# 需要導入模塊: from six import moves [as 別名]
# 或者: from six.moves import filterfalse [as 別名]
def partition(pred, iterable):
    """
    Returns a 2-tuple of iterables derived from the input iterable.
    The first yields the items that have ``pred(item) == False``.
    The second yields the items that have ``pred(item) == True``.

        >>> is_odd = lambda x: x % 2 != 0
        >>> iterable = range(10)
        >>> even_items, odd_items = partition(is_odd, iterable)
        >>> list(even_items), list(odd_items)
        ([0, 2, 4, 6, 8], [1, 3, 5, 7, 9])

    """
    # partition(is_odd, range(10)) --> 0 2 4 6 8   and  1 3 5 7 9
    t1, t2 = tee(iterable)
    return filterfalse(pred, t1), filter(pred, t2) 
開發者ID:pypa,項目名稱:pipenv,代碼行數:18,代碼來源:recipes.py

示例4: find

# 需要導入模塊: from six import moves [as 別名]
# 或者: from six.moves import filterfalse [as 別名]
def find(cls, where='.', exclude=(), include=('*', )):
        """Return a list all Python packages found within directory 'where'

        'where' should be supplied as a "cross-platform" (i.e. URL-style)
        path; it will be converted to the appropriate local path syntax.
        'exclude' is a sequence of package names to exclude; '*' can be used
        as a wildcard in the names, such that 'foo.*' will exclude all
        subpackages of 'foo' (but not 'foo' itself).

        'include' is a sequence of package names to include.  If it's
        specified, only the named packages will be included.  If it's not
        specified, all found packages will be included.  'include' can contain
        shell style wildcard patterns just like 'exclude'.

        The list of included packages is built up first and then any
        explicitly excluded packages are removed from it.
        """
        out = cls._find_packages_iter(convert_path(where))
        out = cls.require_parents(out)
        includes = cls._build_filter(*include)
        excludes = cls._build_filter('ez_setup', '*__pycache__', *exclude)
        out = filter(includes, out)
        out = filterfalse(excludes, out)
        return list(out) 
開發者ID:ywangd,項目名稱:stash,代碼行數:26,代碼來源:pip.py

示例5: drop

# 需要導入模塊: from six import moves [as 別名]
# 或者: from six.moves import filterfalse [as 別名]
def drop(self, pred):
        """Drop items for which pred(item) evaluates to True.

        Note: returns self so it can be chained with other filters, e.g.,

                newseq = seq.select(...).drop(...).transform(...)
        """
        # self._iter = (i for i in self if not pred(i))
        self._iter = filterfalse(pred, self._iter)
        return self 
開發者ID:terrapower,項目名稱:armi,代碼行數:12,代碼來源:iterables.py

示例6: __iter__

# 需要導入模塊: from six import moves [as 別名]
# 或者: from six.moves import filterfalse [as 別名]
def __iter__(self):
        if self.cache_location is not None:
            filenames = iglob(self.filename('*'))
            keys = map(lambda f: os.path.splitext(os.path.basename(f))[0], filenames)
            new_keys = filterfalse(lambda key: key in self._cache.keys(), keys)
            return chain(iterkeys(self._cache), new_keys)
        else:
            return iterkeys(self._cache) 
開發者ID:matthias-k,項目名稱:pysaliency,代碼行數:10,代碼來源:utils.py

示例7: _candidate_dirs

# 需要導入模塊: from six import moves [as 別名]
# 或者: from six.moves import filterfalse [as 別名]
def _candidate_dirs(base_path):
        """
        Return all dirs in base_path that might be packages.
        """
        has_dot = lambda name: '.' in name
        for root, dirs, files in os.walk(base_path, followlinks=True):
            # Exclude directories that contain a period, as they cannot be
            #  packages. Mutate the list to avoid traversal.
            dirs[:] = filterfalse(has_dot, dirs)
            for dir in dirs:
                yield os.path.relpath(os.path.join(root, dir), base_path) 
開發者ID:ywangd,項目名稱:stash,代碼行數:13,代碼來源:pip.py

示例8: partition

# 需要導入模塊: from six import moves [as 別名]
# 或者: from six.moves import filterfalse [as 別名]
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) 
開發者ID:viswanathgs,項目名稱:dist-dqn,代碼行數:11,代碼來源:utils.py

示例9: test_filter_false

# 需要導入模塊: from six import moves [as 別名]
# 或者: from six.moves import filterfalse [as 別名]
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 
開發者ID:benjaminp,項目名稱:six,代碼行數:8,代碼來源:test_six.py

示例10: dfilter

# 需要導入模塊: from six import moves [as 別名]
# 或者: from six.moves import filterfalse [as 別名]
def dfilter(content, blacklist=None, inverse=False):
    """ Filters content

    Args:
        content (dict): The content to filter
        blacklist (Seq[str]): The fields to remove (default: None)
        inverse (bool): Keep fields instead of removing them (default: False)

    See also:
        `meza.process.cut`

    Returns:
        dict: The filtered content

    Examples:
        >>> content = {'keep': 'Hello', 'strip': 'World'}
        >>> dfilter(content) == {'keep': 'Hello', 'strip': 'World'}
        True
        >>> dfilter(content, ['strip']) == {'keep': 'Hello'}
        True
        >>> dfilter(content, ['strip'], True) == {'strip': 'World'}
        True
    """
    blackset = set(blacklist or [])
    func = filterfalse if inverse else filter
    return dict(func(lambda x: x[0] not in blackset, content.items())) 
開發者ID:reubano,項目名稱:meza,代碼行數:28,代碼來源:fntools.py

示例11: to_datetime

# 需要導入模塊: from six import moves [as 別名]
# 或者: from six.moves import filterfalse [as 別名]
def to_datetime(content, dt_format=None, warn=False):
    """Parses and formats strings into datetimes.

    Args:
        content (str): The string to parse.

        dt_format (str): Date format passed to `strftime()`
            (default: None).

        warn (bool): raise error if content can't be safely converted
            (default: False)

    Returns:
        obj: The datetime object or formatted datetime string.

    See also:
        `meza.process.type_cast`

    Examples:
        >>> fmt = '%Y-%m-%d %H:%M:%S'
        >>> to_datetime('5/4/82 2:00 pm')
        datetime.datetime(1982, 5, 4, 14, 0)
        >>> to_datetime('5/4/82 10:00', fmt) == '1982-05-04 10:00:00'
        True
        >>> to_datetime('2/32/82 12:15', fmt) == '1982-02-28 12:15:00'
        True
        >>> to_datetime('spam')
        datetime.datetime(9999, 12, 31, 0, 0)
        >>> to_datetime('spam', warn=True)
        Traceback (most recent call last):
        ValueError: Invalid datetime value: `spam`.

    Returns:
        datetime
    """
    bad_nums = map(str, range(29, 33))
    good_nums = map(str, range(31, 27, -1))

    try:
        bad_num = next(x for x in bad_nums if x in content)
    except StopIteration:
        options = [content]
    else:
        possibilities = (content.replace(bad_num, x) for x in good_nums)
        options = it.chain([content], possibilities)

    # Fix impossible dates, e.g., 2/31/15
    results = filterfalse(lambda x: x[1], map(_to_datetime, options))
    value = next(results)[0]

    if warn and value == DEFAULT_DATETIME:
        raise ValueError('Invalid datetime value: `{}`.'.format(content))
    else:
        datetime = value.strftime(dt_format) if dt_format else value

    return datetime 
開發者ID:reubano,項目名稱:meza,代碼行數:58,代碼來源:convert.py


注:本文中的six.moves.filterfalse方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。