Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for One Switch Strings by PythonLearner
def switch_strings(line: str, result: str) -> bool:
answer = False
if len(line) == len(result):
diffs = [(x, y) for x, y in zip(line, result) if x != y]
if len(diffs) == 2:
(x1, y1), (x2, y2) = diffs
answer = x1 == y2 and y1 == x2
else:
answer = not diffs
return answer
print("Example:")
print(switch_strings("btry", "byrt"))
assert switch_strings("btry", "byrt") == True
assert switch_strings("boss", "boss") == True
assert switch_strings("solid", "disel") == False
assert switch_strings("false", "flaes") == False
assert switch_strings("true", "treu") == True
print("The mission is done! Click 'Check Solution' to earn rewards!")
Oct. 13, 2022