>>> compare_string('0010','0110') '0_10' >>> compare_string('0110','1101') False
(string1: str, string2: str)
| 5 | |
| 6 | |
| 7 | def compare_string(string1: str, string2: str) -> str | Literal[False]: |
| 8 | """ |
| 9 | >>> compare_string('0010','0110') |
| 10 | '0_10' |
| 11 | |
| 12 | >>> compare_string('0110','1101') |
| 13 | False |
| 14 | """ |
| 15 | list1 = list(string1) |
| 16 | list2 = list(string2) |
| 17 | count = 0 |
| 18 | for i in range(len(list1)): |
| 19 | if list1[i] != list2[i]: |
| 20 | count += 1 |
| 21 | list1[i] = "_" |
| 22 | if count > 1: |
| 23 | return False |
| 24 | else: |
| 25 | return "".join(list1) |
| 26 | |
| 27 | |
| 28 | def check(binary: list[str]) -> list[str]: |