def encode_direct(list_a: list):
    """Problem 13: Run-length encoding of a list (direct solution).

    Parameters
    ----------
    list_a : list
        The input list

    Returns
    -------
    list of list
        An length-encoded list

    Raises
    ------
    TypeError
        If the given argument is not of `list` type

    """
    if not isinstance(list_a, list):
        raise TypeError('The argument given is not of `list` type.')

    if len(list_a) <= 1:
        # In case of empty or one-element list return.
        return list_a

    encoded, current, count = [], list_a[0], 1
    for element in list_a[1:]:
        if current != element:
            # If current element does not match the recorded current
            # append the count to the list
            encoded.append(current if count == 1 else [count, current])
            current, count = element, 1
        else:
            # If another same element is found, increase counter
            count += 1
    encoded.append(current if count == 1 else [count, current])

    return encoded