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)
  
      # Any case change counts as a single edit
      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]
docs: Computes the lexical distance between strings A and B.
  
      The "distance" between two strings is given by counting the minimum number of edits
      needed to transform string A into string B. An edit can be an insertion, deletion,
      or substitution of a single character, or a swap of two adjacent characters.
  
      This distance can be useful for detecting typos in input or sorting.