Question: Need help Understanding code and filling the blanks in on the comments (Purpose Assumptions input and output) if you could give a deep explnation of
Need help Understanding code and filling the blanks in on the comments (Purpose Assumptions input and output) if you could give a deep explnation of each function that would be great thank you. from collections import OrderedDict #implementing the class dequeue class deque2: #constructor for the class def __init__(self): #initializing the dictionary for items self.items = OrderedDict() # purpose: add items at the startingl # Assumptions: adding Items to the order dict # Inputs none # Outputs none def add_items(self,val): #adding items to the OrderedDict self.items[val] = 1 #removing items from the front # purpose:removing items from the front # Assumptions: checks if dictionary is empty # Inputs 0 # Outputs 0 def removeFront(self): #check if dictionary is empty if len(self.items) == 0: return return self.items.popitem(0)[0] #removing items from the end # purpose:removing items from the end # Assumptions: removes Rear # Inputs # Outputs def removeRear(self): #check if dictionary is empty if len(self.items) == 0: return return self.items.popitem()[0] #method to get the first items # purpose:method to get the first items # Assumptions: # Inputs # Outputs def get_first(self): #check if dictionary is empty if len(self.items) == 0: return for item in self.items: return item #method to get the last item # purpose: method to get the last item # Assumptions: # Inputs # Outputs def get_last(self): #check if dictionary is empty if len(self.items) == 0: return last = None for item in self.items: last = item return last #driver code to check the functnality def Test(): #testing code d = deque2() d.add_items(2) d.add_items(3) d.add_items(4) d.add_items(5) d.add_items(6) d.add_items(7) print("Item at front is :",d.get_first()) print("Item at the end is :",d.get_last()) print("Item removed :",d.removeRear()) print("Item removed :",d.removeFront()) print("Item at front is :",d.get_first()) print("Item at the end is :",d.get_last()) Test()
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
