code: def lexical_distance(a_str: str, b_str: str) -> int:
      if a_str == b_str:
          return 0
      a, b = a_str.lower(), b_str.lower()
      a_len, b_len = len(a), len(b)
      if a == b:
          return 1
      d = [[j for j in range(0, b_len + 1)]]
      for i in range(1, a_len + 1):
          d.append([i] + [0] * b_len)
      for i in range(1, a_len + 1):
          for j in range(1, b_len + 1):
              cost = 0 if a[i - 1] == b[j - 1] else 1
              d[i][j] = min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost)
              if i > 1 and j > 1 and a[i - 1] == b[j - 2] and a[i - 2] == b[j - 1]:
                  d[i][j] = min(d[i][j], d[i - 2][j - 2] + cost)
      return d[a_len][b_len]