本文整理匯總了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
示例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
示例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
示例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
示例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
示例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)
示例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
示例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
示例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
示例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 ---------------------------
示例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
示例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
示例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
示例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
示例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