You are on page 1of 1

class 

IncreasingList:
    def __init__(self):
        self.list1=[]

    def append(self, val):
        """
        first, it removes all elements from the list that have greater 
values than val, starting from the last one, and once there are no grea
ter element in the list, it appends val to the end of the list
        """
        if len(self.list1) !=0:
            
           for i in range(len(self.list1)-1,-1,-1):
                if self.list1[i]>val:
                    self.list1.pop()
                else:
                     break
        self.list1.append(val)
        

    def pop(self):
        """
        removes the last element from the list if the list is not empty
, otherwise, if the list is empty, it does nothing
        """
        if len(self.list1) != 0:
            self.list1.pop()

    def __len__(self):
        """
        returns the number of elements in the list
        """
        l=0
        for i in self.list1:
            l=l+1
            
        return l

You might also like