from typing import List


def texttoken_to_index(sequence: List[str], VOCAB: List[str]) -> List[int]:
    """Convert a sequence of strings to a sequence of IDs (int) based
        on a given vocabulary

    Parameters:
    -----------
    sequence : List[str]
        List of ID sequences

    VOCAB : List[str]
        Vocabulary list, alphabetically sorted

    Returns:
    --------
    List[int]
        List of ID sequences

    Example:
    --------
        seqs_of_ids = [texttoken_to_index(seq, VOCAB) for seq in sequences]
    """
    # find ID for [UNK], i.e. unknown
    try:
        UNKIDX = VOCAB.index("[UNK]")
    except Exception:
        UNKIDX = len(VOCAB)
    # loop over each token
    indices = []
    for token in sequence:
        try:
            indices.append(VOCAB.index(token))
        except Exception:
            indices.append(UNKIDX)
    # done
    return indices