def list_extract(lst, max_num):
    """ Function used to pop a number of elements from a list equal or less than max_num """

    ret_lst = []
    if len(lst) >= max_num:
        for i in range(max_num):
            ret_lst.append(lst.pop())

    else:  # less elements than max_num
        for i in reversed(range(len(lst))):
            ret_lst.append(lst.pop())

    return ret_lst