(_str1: str, _str2: str)
| 26 | """ |
| 27 | |
| 28 | def get_matched_characters(_str1: str, _str2: str) -> str: |
| 29 | matched = [] |
| 30 | limit = min(len(_str1), len(_str2)) // 2 |
| 31 | for i, char in enumerate(_str1): |
| 32 | left = int(max(0, i - limit)) |
| 33 | right = int(min(i + limit + 1, len(_str2))) |
| 34 | if char in _str2[left:right]: |
| 35 | matched.append(char) |
| 36 | _str2 = ( |
| 37 | f"{_str2[0 : _str2.index(char)]} {_str2[_str2.index(char) + 1 :]}" |
| 38 | ) |
| 39 | |
| 40 | return "".join(matched) |
| 41 | |
| 42 | # matching characters |
| 43 | matching_1 = get_matched_characters(str1, str2) |