def diff_view(str1, str2):
    """ Calculate the lengths of the longest common prefix
    and suffix between str1 and str2.

    Let str1 = axb of length m and str2 = ayb of length n,
    then this function finds and returns i and j such that:
    str1[0:i] = str2[0:i] = a and str1[m-j:] = str2[n-j:] = b.
    In the case that a or b does not exist (no common prefix
    or suffix), then i or j are 0.

    :param str1: the first string
    :param str2: the second string
    :return: common prefix and suffix lengths (i.e. i and j; see description)
    """
    m, n = len(str1), len(str2)
    len_limit = min(m, n)
    prefix_len, suffix_len = 0, 0
    while prefix_len < len_limit and str1[prefix_len] == str2[prefix_len]:
        prefix_len += 1
    # was using negative indexing,
    # I just think this way is better understandable
    while suffix_len < len_limit \
            and str1[m - 1 - suffix_len] == str2[n - 1 - suffix_len]:
        suffix_len += 1
    return prefix_len, suffix_len