<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def fill(xs, length, copy=False):
 """Convert a value to a list of specified length. If the input is too short, fill it with its last element. Parameters xs Input list or value. length : `int` Output list length. copy : `bool`, optional Deep copy the last element to fill the list (default: False). Returns ------- `list` Raises ------ ValueError If `xs` is empty and `length` > 0 Examples -------- [0, 0, 0] [0] [{'x': 0}, {'x': 1}, {'x': 1}, {'x': 1}] True True [{'x': 0}, {'x': 1}, {'x': 1}, {'x': 1}] False False """

    if isinstance(xs, list) and len(xs) == length:
        return xs

    if length <= 0:
        return []

    try:
        xs = list(islice(xs, 0, length))
        if not xs:
            raise ValueError('empty input')
    except TypeError:
        xs = [xs]

    if len(xs) < length:
        if copy:
            last = xs[-1]
            xs.extend(deepcopy(last) for _ in range(length - len(xs)))
        else:
            xs.extend(islice(repeat(xs[-1]), 0, length - len(xs)))

    return xs