from typing import List
from typing import Dict


def word_index(los: List[List[str]], vocab_dict: Dict[str, int], unknown: int, reverse: bool=False) -> List[List[int]]:
    """
    Replaces words with integers from a vocabulary dictionary or else with the integer for unknown
    
    Args:
        los:     list of lists of split sentences
        pad_to:  how big to make the padded list
        unknown: the integer to put in for unknown tokens (either because they were pruned or not seen in training set)
        reverse: reverse the order of tokens in the sub-list 
    Returns: 
        new_los: list of lists of split sentences where each token is replaced by an integer
        
    Examples:
    >>> print(word_index([['one', 'two', 'three'], ['one', 'two']], {'one': 1, 'two': 2, 'three': 3}, unknown=4))
    [[1, 2, 3], [1, 2]]
    >>> print(word_index([['one', 'two', 'three'], ['one', 'two']], {'one': 1, 'two': 2, 'three': 3}, unknown=4, reverse=True))
    [[3, 2, 1], [2, 1]]
    """
    new_los = []
    if reverse:
        for sentence in los:
            new_los.append([vocab_dict[word] if word in vocab_dict else unknown for word in sentence][::-1])        
    else:
        for sentence in los:
            new_los.append([vocab_dict[word] if word in vocab_dict else unknown for word in sentence])
    return new_los