(
    aug_toks: List[types.AugTok], *, num: int | float = 1
)
return new_aug_toks
Randomly swap two *adjacent* characters in randomly-selected words,
    up to ``num`` times or with a probability of ``num``.

    Args:
        aug_toks: Sequence of tokens to augment through character swapping.
        num: If int, maximum number of words to modify with a random character swap;
            if float, probability that a given word will be modified.

    Returns:
        New, augmented sequence of tokens.
Randomly swap two *adjacent* characters in randomly-selected words,
    up to ``num`` times or with a probability of ``num``.
Randomly swap two * adjacent * characters in randomly - selected words up to num times or with a probability of num .
def swap_chars(
    aug_toks: List[types.AugTok], *, num: int | float = 1
) -> List[types.AugTok]:
    """
    Randomly swap two *adjacent* characters in randomly-selected words,
    up to ``num`` times or with a probability of ``num``.

    Args:
        aug_toks: Sequence of tokens to augment through character swapping.
        num: If int, maximum number of words to modify with a random character swap;
            if float, probability that a given word will be modified.

    Returns:
        New, augmented sequence of tokens.
    """
    _validate_aug_toks(aug_toks)
    cand_idxs = [
        idx
        for idx, aug_tok in enumerate(aug_toks)
        if aug_tok.is_word and len(aug_tok.text) >= 3
    ]
    rand_idxs = set(_select_random_candidates(cand_idxs, num))
    if not rand_idxs:
        return aug_toks[:]

    new_aug_toks = []
    for idx, aug_tok in enumerate(aug_toks):
        if idx in rand_idxs:
            text_list = list(aug_tok.text)
            idx = random.choice(range(1, len(text_list)))
            text_list[idx - 1], text_list[idx] = text_list[idx], text_list[idx - 1]
            new_aug_toks.append(
                types.AugTok(
                    text="".join(text_list),
                    ws=aug_tok.ws,
                    pos=aug_tok.pos,
                    is_word=aug_tok.is_word,
                    syns=aug_tok.syns,
                )
            )
        else:
            new_aug_toks.append(aug_tok)
    return new_aug_toks
def swap_chars ( aug_toks : List [ types . AugTok ] , * , num : int | float = 1 ) -> List [ types . AugTok ] : _validate_aug_toks ( aug_toks ) cand_idxs = [ idx for idx , aug_tok in enumerate ( aug_toks ) if aug_tok . is_word and len ( aug_tok . text ) >= 3 ] rand_idxs = set ( _select_random_candidates ( cand_idxs , num ) ) if not rand_idxs : return aug_toks [ : ] new_aug_toks = [ ] for idx , aug_tok in enumerate ( aug_toks ) : if idx in rand_idxs : text_list = list ( aug_tok . text ) idx = random . choice ( range ( 1 , len ( text_list ) ) ) text_list [ idx - 1 ] , text_list [ idx ] = text_list [ idx ] , text_list [ idx - 1 ] new_aug_toks . append ( types . AugTok ( text = "" . join ( text_list ) , ws = aug_tok . ws , pos = aug_tok . pos , is_word = aug_tok . is_word , syns = aug_tok . syns , ) ) else : new_aug_toks . append ( aug_tok ) return new_aug_toks