Fuzzy String Matching

Fuzzy String Matching

Given two strings and a permissible number of character differences, determine if the strings can be considered approximately equal.

example

Input: Three arguments: two strings (str) and one integer (int).

Output: Logic value (bool).

Examples:

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

How it’s used:

  • spell-checking algorithms where slight differences can be ignored;
  • searching algorithms in databases to find entries that closely match the query;
  • DNA sequence matching where certain differences might be allowed.

Precondition:

  • 0 <= threshold <= max(len(str1), len(str2)).