

def is_one_edit_distance(s, t):
    for i in xrange(min(len(s), len(t))):
        if s[i] != t[i]:
            if len(s) > len(t):
                return s[i + 1:] == t[i:]
            elif len(s) < len(t):
                return s[i:] == t[i + 1:]
            else:
                return s[i + 1:] == t[i + 1:]

    return abs(len(s) - len(t)) == 1


if __name__ == '__main__':
    print is_one_edit_distance('ab', 'cab')