import torch


def string_to_tensor(string, char_list):
    """A helper function to create a target-tensor from a target-string

    params:
        string - the target-string
        char_list - the ordered list of characters

    output: a torch.tensor of shape (len(string)). The entries are the 1-shifted
        indices of the characters in the char_list (+1, as 0 represents the blank-symbol)
    """
    target = []
    for char in string:
        pos = char_list.index(char) + 1
        target.append(pos)

    result = torch.tensor(target, dtype=torch.int32)
    return result