def char_pad_trunc(data, maxlen):
    ' We truncate to maxlen or add in PAD tokens '
    new_dataset = []
    for sample in data:
        if (len(sample) > maxlen):
            new_data = sample[:maxlen]
        elif (len(sample) < maxlen):
            pads = (maxlen - len(sample))
            new_data = (sample + (['PAD'] * pads))
        else:
            new_data = sample
        new_dataset.append(new_data)
    return new_dataset
We truncate to maxlen or add in PAD tokens
def char_pad_trunc(data, maxlen):
    '  '
    new_dataset = []
    for sample in data:
        if (len(sample) > maxlen):
            new_data = sample[:maxlen]
        elif (len(sample) < maxlen):
            pads = (maxlen - len(sample))
            new_data = (sample + (['PAD'] * pads))
        else:
            new_data = sample
        new_dataset.append(new_data)
    return new_dataset