Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Zip_longest save us solution in Clear category for Fuzzy String Matching by Kolia951
from itertools import zip_longest
def fuzzy_string_match(str1: str, str2: str, threshold: int) -> bool:
pair = zip_longest(str1, str2)
difference = sum([1 for a,b in pair if a != b ])
return difference <= threshold
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!")
Nov. 17, 2023