Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Fuzzy String Matching by Julia_Swiatek
def fuzzy_string_match(str1: str, str2: str, threshold: int) -> bool:
# your code here
return False
def fuzzy_string_match(str1, str2, threshold):
if not (0 <= threshold <= max(len(str1), len(str2))):
return False
differences = sum(c1 != c2 for c1, c2 in zip(str1, str2))
if differences <= threshold and abs(len(str1) - len(str2)) <= threshold:
return True
return False
print("Example:")
print(fuzzy_string_match("apple", "appel", 2))
# These "asserts" are used for self-checking
assert fuzzy_string_match("apple", "appel", 2) == True
assert fuzzy_string_match("apple", "bpple", 1) == True
assert fuzzy_string_match("apple", "bpple", 0) == False
assert fuzzy_string_match("apple", "apples", 1) == True
assert fuzzy_string_match("apple", "bpples", 2) == True
assert fuzzy_string_match("apple", "apxle", 1) == True
assert fuzzy_string_match("apple", "pxxli", 3) == False
print("The mission is done! Click 'Check Solution' to earn rewards!")
Jan. 18, 2024