import copy


def train(data, input_model = {'START':[], 'END':[]}):
    """Trains a model using the input data and outputs a dictionary.

    Args:
        data(list) : This is the input data and the training will be based on.
        input_mode(dict) : This can be another pre trained model that includes words as keys and lists of next words.
    
    Return:
        returns a trained model which is a dictionary that has words as keys and lists of next words as elements.
    """
    model = copy.deepcopy(input_model) #Clone the input functiont to prevent affectin the input model.
    for i, element in enumerate(data):
        if i == len(data)-1:
            model['END'].append(element)
        else:
            if i == 1:
                model['START'].append(element)
            
            if element in model:
                model[element].append(data[i+1])
            else:
                model[element] = [data[i+1]]

    return model