def seq_match(exseq, inseq, allowMismatch):
    """
    Return True if <exseq> and <inseq> are same length and either
    (1) identical OR
    (2) has at most one mismatch (if allowMismatch is True)

    :return: bool, num_mismatch
    """
    if len(exseq)!=len(inseq):
        return False, None
    elif exseq == inseq:
        return True, 0
    elif allowMismatch:
        # allow at most one mismatch
        num_mismatch = 0
        for a,b in zip(exseq, inseq):
            if a!=b:
                if num_mismatch == 1: return False, None  # second mismatch, return False!
                else: num_mismatch += 1
        return True, num_mismatch
    else:
        return False, None