MCPcopy Index your code
hub / github.com/python/cpython / _simplify

Method _simplify

Tools/cases_generator/stack.py:97–113  ·  view source on GitHub ↗
(positive: tuple[str, ...], negative: tuple[str, ...])

Source from the content-addressed store, hash-verified

95
96 @staticmethod
97 def _simplify(positive: tuple[str, ...], negative: tuple[str, ...]) -> tuple[tuple[str, ...], tuple[str, ...]]:
98 p_orig: list[str] = sorted(positive)
99 n_orig: list[str] = sorted(negative)
100 p_uniq: list[str] = []
101 n_uniq: list[str] = []
102 while p_orig and n_orig:
103 p_item = p_orig.pop()
104 n_item = n_orig.pop()
105 if p_item > n_item:
106 # if p_item > n_item, there can be no element in n matching p_item.
107 p_uniq.append(p_item)
108 n_orig.append(n_item)
109 elif p_item < n_item:
110 n_uniq.append(n_item)
111 p_orig.append(p_item)
112 # Otherwise they are the same and cancel each other out
113 return tuple(p_orig + p_uniq), tuple(n_orig + n_uniq)
114
115 def to_c(self) -> str:
116 symbol_offset = ""

Callers 1

createMethod · 0.45

Calls 2

popMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected