def fill_with_last(lst, k):
    """
    extend a list to length k by duplicating last item

    >>> fill_with_last([1, 2, 3], 5)
    [1, 2, 3, 3, 3]
    """
    len_l = len(lst)
    if len_l < k:
        lst.extend([lst[-1]] * (k - len_l))
    return lst