def adjust_list_to_length(obj, desired_length):
    """
    Returns a :obj:`list` of length :samp:`{desired_length}`,
    by extending or truncating the :samp:`obj` :obj:`list`.
    The sequence is extended by repeating the last element
    of :samp:`{obj}`.

    :type obj: sequence or :obj:`str`
    :param obj: The sequence to be extended/truncated.
       If :samp:`{obj}` is a string, it is converted to
       a list using :samp:`{obj} = [{obj}, ]`.
    :type desired_length: :obj:`int`
    :param desired_length: The length of the returned :obj:`list`.
    :rtype: :obj:`list`
    :return: A :obj:`list` of length :samp:`{desired_length}
       which contains the elements of the :samp:`{obj}` sequence.
    """
    if isinstance(obj, str):
        obj = [obj, ]
    ret_list = list(obj)
    if len(ret_list) < desired_length:
        ret_list = ret_list + [ret_list[-1], ] * (desired_length - len(ret_list))
    elif len(ret_list) > desired_length:
        ret_list = ret_list[:desired_length]

    return ret_list