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


Python itertools.filterfalse方法代碼示例

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


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

示例1: mean

# 需要導入模塊: import itertools [as 別名]
# 或者: from itertools import filterfalse [as 別名]
def mean(l, ignore_nan=False, empty=0):
    """
    nanmean compatible with generators.
    """
    l = iter(l)
    if ignore_nan:
        l = ifilterfalse(isnan, l)
    try:
        n = 1
        acc = next(l)
    except StopIteration:
        if empty == 'raise':
            raise ValueError('Empty mean')
        return empty
    for n, v in enumerate(l, 2):
        acc += v
    if n == 1:
        return acc
    return acc / n 
開發者ID:edwardzhou130,項目名稱:PolarSeg,代碼行數:21,代碼來源:lovasz_losses.py

示例2: unique_everseen

# 需要導入模塊: import itertools [as 別名]
# 或者: from itertools 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
    # straight from the docs, https://docs.python.org/3/library/itertools.html#itertools-recipes
    seen = set()
    seen_add = seen.add
    if key is None:
        for element in itertools.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:MolSSI,項目名稱:QCElemental,代碼行數:19,代碼來源:itertools.py

示例3: _need_update

# 需要導入模塊: import itertools [as 別名]
# 或者: from itertools import filterfalse [as 別名]
def _need_update(curr_list, desired_list):
    """
    Checks to see if there are any difference in curr_list or desired_list. If they are different this returns True.

    Args:
        curr_list (list): list of dictionaries
        desired_list (list): list of dictionaries

    Returns:
         bool
    """
    #Checks if items need to be added or removed.
    add = list(itertools.filterfalse(lambda x: x in curr_list, desired_list))
    remove = list(itertools.filterfalse(lambda x: x in desired_list, curr_list))
    if add or remove:
        return True
    return False 
開發者ID:capitalone,項目名稱:Particle-Cloud-Framework,代碼行數:19,代碼來源:elb.py

示例4: _need_update

# 需要導入模塊: import itertools [as 別名]
# 或者: from itertools import filterfalse [as 別名]
def _need_update(self, curr_list, desired_list):
        """
        Checks to see if there are any difference in curr_list or desired_list. If they are different this returns True.

        Args:
            curr_list (list): list of dictionaries
            desired_list (list): list of dictionaries

        Returns:
            bool
        """
        #Checks if items need to be added or removed.
        add = list(itertools.filterfalse(lambda x: x in curr_list, desired_list))
        remove = list(itertools.filterfalse(lambda x: x in desired_list, curr_list))
        if add or remove:
            return True
        return False 
開發者ID:capitalone,項目名稱:Particle-Cloud-Framework,代碼行數:19,代碼來源:alb.py

示例5: _need_update

# 需要導入模塊: import itertools [as 別名]
# 或者: from itertools import filterfalse [as 別名]
def _need_update(self, curr_list, desired_list):
        """
        Checks to see if there are any differences in curr_list or desired_list. If they are different True is returned.

        Args:
            curr_list (list): list of dictionaries
            desired_list (list): list of dictionaries

        Returns:
             bool
        """
        # Checks if items need to be added or removed.
        add = list(itertools.filterfalse(lambda x: x in curr_list, desired_list))
        remove = list(itertools.filterfalse(lambda x: x in desired_list, curr_list))
        if add or remove:
            return True
        return False 
開發者ID:capitalone,項目名稱:Particle-Cloud-Framework,代碼行數:19,代碼來源:dynamodb_table.py

示例6: filter_control

# 需要導入模塊: import itertools [as 別名]
# 或者: from itertools import filterfalse [as 別名]
def filter_control(
        cls, segments: Iterable["Segment"], is_control=False
    ) -> Iterable["Segment"]:
        """Filter segments by ``is_control`` attribute.

        Args:
            segments (Iterable[Segment]): An iterable of Segment instances.
            is_control (bool, optional): is_control flag to match in search.

        Returns:
            Iterable[Segment]: And iterable of Segment instances.
        
        """
        if is_control:
            return filter(attrgetter("is_control"), segments)
        else:
            return filterfalse(attrgetter("is_control"), segments) 
開發者ID:willmcgugan,項目名稱:rich,代碼行數:19,代碼來源:segment.py

示例7: mean

# 需要導入模塊: import itertools [as 別名]
# 或者: from itertools import filterfalse [as 別名]
def mean(l, ignore_nan=False, empty=0):
    """
    nanmean compatible with generators.
    """
    l = iter(l)
    if ignore_nan:
        l = filterfalse(np.isnan, l)
    try:
        n = 1
        acc = next(l)
    except StopIteration:
        if empty == 'raise':
            raise ValueError('Empty mean')
        return empty
    for n, v in enumerate(l, 2):
        acc += v
    if n == 1:
        return acc
    return acc / n 
開發者ID:ansleliu,項目名稱:LightNet,代碼行數:21,代碼來源:utils.py

示例8: unique_everseen

# 需要導入模塊: import itertools [as 別名]
# 或者: from itertools import filterfalse [as 別名]
def unique_everseen(iterable, key=None):
    """List unique elements, preserving order. Remember all elements ever seen.

    >>> ''.join(unique_everseen('AAAABBBCCDAABBB'))
    'ABCD'
    >>> ''.join(unique_everseen('ABBCcAD', str.lower))
    'ABCD'

    """
    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:bioinformed,項目名稱:vgraph,代碼行數:23,代碼來源:iterstuff.py

示例9: unique_everseen

# 需要導入模塊: import itertools [as 別名]
# 或者: from itertools import filterfalse [as 別名]
def unique_everseen(iterable, key=None):
    """List unique elements, preserving order. Remember all elements ever seen.

    >>> list(unique_everseen('AAAABBBCCDAABBB'))
    ['A', 'B', 'C', 'D']
    >>> list(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:tensorwerk,項目名稱:hangar-py,代碼行數:22,代碼來源:utils.py

示例10: mean

# 需要導入模塊: import itertools [as 別名]
# 或者: from itertools import filterfalse [as 別名]
def mean(l, ignore_nan=False, empty=0):
    """
    nanmean compatible with generators.
    """
    l = iter(l)
    if ignore_nan:
        l = filterfalse(isnan, l)
    try:
        n = 1
        acc = next(l)
    except StopIteration:
        if empty == "raise":
            raise ValueError("Empty mean")
        return empty
    for n, v in enumerate(l, 2):
        acc += v
    if n == 1:
        return acc
    return acc / n


# --------------------------- Convinient classes --------------------------- 
開發者ID:bonlime,項目名稱:pytorch-tools,代碼行數:24,代碼來源:lovasz.py

示例11: _op_descendants

# 需要導入模塊: import itertools [as 別名]
# 或者: from itertools import filterfalse [as 別名]
def _op_descendants(self, op, only):
        """Descendants of the given operator in the quantum circuit.

        Args:
            op (Operator): operator in the quantum circuit
            only (str, None): the type of descendants to return.

                - ``'G'``: only return non-observables (default)
                - ``'O'``: only return observables
                - ``None``: return all descendants

        Returns:
            list[Operator]: descendants in a topological order
        """
        succ = self.circuit.descendants_in_order((op,))
        if only == "O":
            return list(filter(_is_observable, succ))
        if only == "G":
            return list(itertools.filterfalse(_is_observable, succ))
        return succ 
開發者ID:XanaduAI,項目名稱:pennylane,代碼行數:22,代碼來源:base.py

示例12: unique_everseen

# 需要導入模塊: import itertools [as 別名]
# 或者: from itertools import filterfalse [as 別名]
def unique_everseen(iterable, key=None):
    """List unique elements, preserving order.

    Remember all elements ever seen

    >>> list(unique_everseen('AAAABBBCCDAABBB'))
    ['A', 'B', 'C', 'D']
    >>> list(unique_everseen('ABBCcAD', str.lower))
    ['A', 'B', 'C', 'D']

    """
    seen = set()
    seen_add = seen.add
    if key is None:
        for element in itertools.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:KarlJorgensen,項目名稱:virgin-media-hub3,代碼行數:25,代碼來源:utils.py

示例13: mean

# 需要導入模塊: import itertools [as 別名]
# 或者: from itertools import filterfalse [as 別名]
def mean(l, ignore_nan=True, empty=0):
    """
    nanmean compatible with generators.
    """
    l = iter(l)
    if ignore_nan:
        l = filterfalse(isnan, l)
    try:
        n = 1
        acc = next(l)
    except StopIteration:
        if empty == 'raise':
            raise ValueError('Empty mean')
        return empty
    for n, v in enumerate(l, 2):
        acc += v
    if n == 1:
        return acc
    return acc / n 
開發者ID:lyakaap,項目名稱:pytorch-template,代碼行數:21,代碼來源:losses.py

示例14: mean

# 需要導入模塊: import itertools [as 別名]
# 或者: from itertools import filterfalse [as 別名]
def mean(values, ignore_nan=False, empty=0):
    """
    Nanmean compatible with generators.
    """
    values = iter(values)
    if ignore_nan:
        values = ifilterfalse(isnan, values)
    try:
        n = 1
        acc = next(values)
    except StopIteration:
        if empty == "raise":
            raise ValueError("Empty mean")
        return empty
    for n, v in enumerate(values, 2):  # noqa: B007
        acc += v
    if n == 1:
        return acc
    return acc / n 
開發者ID:catalyst-team,項目名稱:catalyst,代碼行數:21,代碼來源:lovasz.py

示例15: get_parsed_py_files

# 需要導入模塊: import itertools [as 別名]
# 或者: from itertools import filterfalse [as 別名]
def get_parsed_py_files(self, whitelist=None):
        parsed_py_files = self._parsed_py_files
        if whitelist:
            parsed_py_files = filterfalse(
                lambda parsed_file: parsed_file.is_in_whitelist(whitelist),
                parsed_py_files
            )
        return parsed_py_files 
開發者ID:devmanorg,項目名稱:fiasko_bro,代碼行數:10,代碼來源:repository_info.py


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