def word_to_index(vocab):
    """
    Encoding words by indexing.

    Parameters
    ----------
        vocab: list.

    Returns
    -------
        word_to_idx dictionary.
    """
    word_to_idx = {}

    for word in vocab:
        word_to_idx[word] = len(word_to_idx)

    return word_to_idx