Raise error not string (#7945)
* ci: Add `B023` to `.flake8` ignores * refactor: Return `bool`/raise Exception * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * revert: Remove previous branch commit * Update data_structures/binary_tree/segment_tree_other.py Co-authored-by: Christian Clauss <cclauss@me.com> * feat: Apply `__repr__` changes * chore: Fix failing tests * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update data_structures/binary_tree/segment_tree_other.py Co-authored-by: Christian Clauss <cclauss@me.com> * test: Fix doctests * random.choice(population_score[:N_SELECTED])[0] * Update basic_string.py Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Christian Clauss <cclauss@me.com>
This commit is contained in:
co-authored by
Christian Clauss
pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
parent
51708530b6
commit
daa1c7529a
@@ -1,15 +1,16 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Sequence
|
||||
from typing import Literal
|
||||
|
||||
|
||||
def compare_string(string1: str, string2: str) -> str:
|
||||
def compare_string(string1: str, string2: str) -> str | Literal[False]:
|
||||
"""
|
||||
>>> compare_string('0010','0110')
|
||||
'0_10'
|
||||
|
||||
>>> compare_string('0110','1101')
|
||||
'X'
|
||||
False
|
||||
"""
|
||||
list1 = list(string1)
|
||||
list2 = list(string2)
|
||||
@@ -19,7 +20,7 @@ def compare_string(string1: str, string2: str) -> str:
|
||||
count += 1
|
||||
list1[i] = "_"
|
||||
if count > 1:
|
||||
return "X"
|
||||
return False
|
||||
else:
|
||||
return "".join(list1)
|
||||
|
||||
@@ -36,10 +37,10 @@ def check(binary: list[str]) -> list[str]:
|
||||
for i in range(len(binary)):
|
||||
for j in range(i + 1, len(binary)):
|
||||
k = compare_string(binary[i], binary[j])
|
||||
if k != "X":
|
||||
if k is False:
|
||||
check1[i] = "*"
|
||||
check1[j] = "*"
|
||||
temp.append(k)
|
||||
temp.append("X")
|
||||
for i in range(len(binary)):
|
||||
if check1[i] == "$":
|
||||
pi.append(binary[i])
|
||||
|
||||
Reference in New Issue
Block a user