本文整理汇总了Python中operator.is_not方法的典型用法代码示例。如果您正苦于以下问题:Python operator.is_not方法的具体用法?Python operator.is_not怎么用?Python operator.is_not使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类operator
的用法示例。
在下文中一共展示了operator.is_not方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_operator
# 需要导入模块: import operator [as 别名]
# 或者: from operator import is_not [as 别名]
def test_operator(self):
import operator
self.assertIs(operator.truth(0), False)
self.assertIs(operator.truth(1), True)
with test_support.check_py3k_warnings():
self.assertIs(operator.isCallable(0), False)
self.assertIs(operator.isCallable(len), True)
self.assertIs(operator.isNumberType(None), False)
self.assertIs(operator.isNumberType(0), True)
self.assertIs(operator.not_(1), False)
self.assertIs(operator.not_(0), True)
self.assertIs(operator.isSequenceType(0), False)
self.assertIs(operator.isSequenceType([]), True)
self.assertIs(operator.contains([], 1), False)
self.assertIs(operator.contains([1], 1), True)
self.assertIs(operator.isMappingType(1), False)
self.assertIs(operator.isMappingType({}), True)
self.assertIs(operator.lt(0, 0), False)
self.assertIs(operator.lt(0, 1), True)
self.assertIs(operator.is_(True, True), True)
self.assertIs(operator.is_(True, False), False)
self.assertIs(operator.is_not(True, True), False)
self.assertIs(operator.is_not(True, False), True)
示例2: trans_result
# 需要导入模块: import operator [as 别名]
# 或者: from operator import is_not [as 别名]
def trans_result(self, rv, op_name, threshold):
"""
对结果进行转化,最后结果为 True/False 标识是否命中
:param bool|None rv: 内置函数返回值
:param str|unicode op_name: 操作符
:param object threshold: 阈值
:return:
"""
# 若想忽略op码永远通过则设置rv为None
if rv is None:
return False
if op_name in {'is', 'is_not'}:
threshold = True
elif self.threshold_trans_func:
threshold = self.threshold_trans_func(threshold)
method = self.op_map.get(op_name, None)
return method(rv, threshold) if method else False
示例3: test_operator
# 需要导入模块: import operator [as 别名]
# 或者: from operator import is_not [as 别名]
def test_operator(self):
import operator
self.assertIs(operator.truth(0), False)
self.assertIs(operator.truth(1), True)
self.assertIs(operator.isCallable(0), False)
self.assertIs(operator.isCallable(len), True)
self.assertIs(operator.isNumberType(None), False)
self.assertIs(operator.isNumberType(0), True)
self.assertIs(operator.not_(1), False)
self.assertIs(operator.not_(0), True)
self.assertIs(operator.isSequenceType(0), False)
self.assertIs(operator.isSequenceType([]), True)
self.assertIs(operator.contains([], 1), False)
self.assertIs(operator.contains([1], 1), True)
self.assertIs(operator.isMappingType(1), False)
self.assertIs(operator.isMappingType({}), True)
self.assertIs(operator.lt(0, 0), False)
self.assertIs(operator.lt(0, 1), True)
self.assertIs(operator.is_(True, True), True)
self.assertIs(operator.is_(True, False), False)
self.assertIs(operator.is_not(True, True), False)
self.assertIs(operator.is_not(True, False), True)
示例4: __init__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import is_not [as 别名]
def __init__(self, tokens):
super().__init__(tokens)
self.operator_map = {
"<": operator.lt,
"<=": operator.le,
">": operator.gt,
">=": operator.ge,
"==": operator.eq,
"!=": operator.ne,
"in": EvalLogic.in_,
"not in": EvalLogic.not_in,
"is": operator.is_,
"is not": operator.is_not,
"isdisjoint": lambda a, b: a.isdisjoint(b),
"and": operator.and_,
"or": operator.or_,
}
示例5: from_str
# 需要导入模块: import operator [as 别名]
# 或者: from operator import is_not [as 别名]
def from_str(cls, version_str):
""" Parse version information from a string. """
matches = Semver.SEMVER_RE.match(version_str)
if matches:
args = list(matches.groups())
if not matches.group(3):
args.append('0')
return Semver(*map(int, filter(partial(is_not, None), args)))
parts = parse(version_str)
return cls(
parts['major'],
parts['minor'],
parts['patch'],
parts['prerelease'],
parts['build']
)
示例6: iter_compare_dicts
# 需要导入模块: import operator [as 别名]
# 或者: from operator import is_not [as 别名]
def iter_compare_dicts(dict1, dict2, only_common_keys=False, comparison_op=operator.ne):
"""
A generator for comparation of values in the given two dicts.
Yields the tuples (key, pair of values positively compared).
By default, the *difference* of values is evaluated using the usual != op, but can be changed
by passing other comparison_op (a function of two arguments returning True/False).
For example: operator.eq for equal values, operator.is_not for not identical objects.
You can also require comparison only over keys existing in both dicts (only_common_keys=True).
Otherwise, you will get the pair with the Python built-in Ellipsis placed for dict with
that key missing. (Be sure to test for Ellipsis using the 'is' operator.)
>>> d1 = dict(a=1, b=2, c=3)
>>> d2 = dict(a=1, b=20, d=4)
>>> dict(iter_compare_dicts(d1, d2, only_common_keys=True))
{'b': (2, 20)}
>>> dict(iter_compare_dicts(d1, d2, only_common_keys=True, comparison_op=operator.eq))
{'a': (1, 1)}
>>> dict(iter_compare_dicts(d1, d2))
{'c': (3, Ellipsis), 'b': (2, 20), 'd': (Ellipsis, 4)}
>>> dict(iter_compare_dicts(d1, d2, comparison_op=operator.eq))
{'a': (1, 1), 'c': (3, Ellipsis), 'd': (Ellipsis, 4)}
"""
keyset1, keyset2 = set(dict1), set(dict2)
for key in (keyset1 & keyset2):
pair = (dict1[key], dict2[key])
if reduce(comparison_op, pair):
yield key, pair
if not only_common_keys:
for key in (keyset1 - keyset2):
yield key, (dict1[key], Ellipsis)
for key in (keyset2 - keyset1):
yield key, (Ellipsis, dict2[key])
示例7: test_is_not
# 需要导入模块: import operator [as 别名]
# 或者: from operator import is_not [as 别名]
def test_is_not(self):
a = b = 'xyzpdq'
c = a[:3] + b[3:]
self.assertRaises(TypeError, operator.is_not)
self.assertFalse(operator.is_not(a, b))
self.assertTrue(operator.is_not(a,c))
示例8: reduce
# 需要导入模块: import operator [as 别名]
# 或者: from operator import is_not [as 别名]
def reduce(self, func):
rs = [r.result() for r in self._submit_to_pool(func, do_reduce)]
rs = [r for r in filter(partial(is_not, None), rs)]
if len(rs) <= 0:
return None
rtn = rs[0]
for r in rs[1:]:
rtn = func(rtn, r)
return rtn
示例9: test_operator
# 需要导入模块: import operator [as 别名]
# 或者: from operator import is_not [as 别名]
def test_operator(self):
import operator
self.assertIs(operator.truth(0), False)
self.assertIs(operator.truth(1), True)
self.assertIs(operator.not_(1), False)
self.assertIs(operator.not_(0), True)
self.assertIs(operator.contains([], 1), False)
self.assertIs(operator.contains([1], 1), True)
self.assertIs(operator.lt(0, 0), False)
self.assertIs(operator.lt(0, 1), True)
self.assertIs(operator.is_(True, True), True)
self.assertIs(operator.is_(True, False), False)
self.assertIs(operator.is_not(True, True), False)
self.assertIs(operator.is_not(True, False), True)
示例10: execute_agents
# 需要导入模块: import operator [as 别名]
# 或者: from operator import is_not [as 别名]
def execute_agents(self, command: State, agents: List[Agent]) -> List[Union[Action, List[Action]]]:
with futures.ThreadPoolExecutor(max_workers=self.NUM_WORKERS) as executor:
done, _ = futures.wait(
[executor.submit(plugin_instance.execute, command) for plugin_instance in agents],
timeout=self.MAX_TIME_PLUGIN_EXECUTION)
if not done:
return []
results = map(lambda future: future.result(), done)
candidate_actions = list(filter(partial(is_not, None), results))
return candidate_actions
# pylint: disable= invalid-name
示例11: is_not
# 需要导入模块: import operator [as 别名]
# 或者: from operator import is_not [as 别名]
def is_not(x, y):
"""Implementation of the `is not` operator."""
return not (x is y)
示例12: to_int_arr
# 需要导入模块: import operator [as 别名]
# 或者: from operator import is_not [as 别名]
def to_int_arr(inputs):
if inputs is not None:
if isinstance(inputs, six.string_types):
inputs = re.split(',| ', inputs)
ints = map(to_int, inputs)
ret = list(filter(partial(is_not, None), ints))
else:
ret = []
return ret
示例13: test_is_not
# 需要导入模块: import operator [as 别名]
# 或者: from operator import is_not [as 别名]
def test_is_not(self):
a = b = 'xyzpdq'
c = a[:3] + b[3:]
self.failUnlessRaises(TypeError, operator.is_not)
self.failIf(operator.is_not(a, b))
self.failUnless(operator.is_not(a,c))
示例14: compute_npmi
# 需要导入模块: import operator [as 别名]
# 或者: from operator import is_not [as 别名]
def compute_npmi(self, topics, num_words=10):
"""
Compute global NPMI across topics
Parameters
----------
topics: ``List[Tuple[str, List[int]]]``
list of learned topics
num_words: ``int``
number of words to compute npmi over
"""
topics_idx = [[self._ref_vocab_index.get(word)
for word in topic[1][:num_words]] for topic in topics]
rows = []
cols = []
res_rows = []
res_cols = []
max_seq_len = max([len(topic) for topic in topics_idx])
for index, topic in enumerate(topics_idx):
topic = list(filter(partial(is_not, None), topic))
if len(topic) > 1:
_rows, _cols = zip(*combinations(topic, 2))
res_rows.extend([index] * len(_rows))
res_cols.extend(range(len(_rows)))
rows.extend(_rows)
cols.extend(_cols)
npmi_data = ((np.log10(self.n_docs) + self._npmi_numerator[rows, cols])
/ (np.log10(self.n_docs) - self._npmi_denominator[rows, cols]))
npmi_data[npmi_data == 1.0] = 0.0
npmi_shape = (len(topics), len(list(combinations(range(max_seq_len), 2))))
npmi = sparse.csr_matrix((npmi_data.tolist()[0], (res_rows, res_cols)), shape=npmi_shape)
return npmi.mean()
示例15: get_records_participated_in_by_user
# 需要导入模块: import operator [as 别名]
# 或者: from operator import is_not [as 别名]
def get_records_participated_in_by_user():
_current_user_id = int(current_user.get_id())
as_uploader = SubmissionParticipant.query.filter_by(user_account=_current_user_id, role='uploader').order_by(
SubmissionParticipant.id.desc()).all()
as_reviewer = SubmissionParticipant.query.filter_by(user_account=_current_user_id, role='reviewer').order_by(
SubmissionParticipant.id.desc()).all()
as_coordinator_query = HEPSubmission.query.filter_by(coordinator=_current_user_id).order_by(
HEPSubmission.created.desc())
# special case, since this user ID is the one used for loading all submissions, which is in the 1000s.
if _current_user_id == 1:
as_coordinator_query = as_coordinator_query.limit(5)
as_coordinator = as_coordinator_query.all()
result = {'uploader': [], 'reviewer': [], 'coordinator': []}
if as_uploader:
_uploader = [get_record_contents(x.publication_recid) for x in as_uploader]
result['uploader'] = filter(partial(is_not, None), _uploader)
if as_reviewer:
_uploader = [get_record_contents(x.publication_recid) for x in as_reviewer]
result['reviewer'] = filter(partial(is_not, None), _uploader)
if as_coordinator:
_coordinator = [get_record_contents(x.publication_recid) for x in as_coordinator]
result['coordinator'] = filter(partial(is_not, None), _coordinator)
return list(result)