Question: python please Continuing on from the previous question, extend the Queue class by adding the to_list (self) method that returns all the elements from the

python please Continuing on from the previous question, extend the Queue classpython please

Continuing on from the previous question, extend the Queue class by adding the to_list (self) method that returns all the elements from the queue as a new Python List. The function should copy elements from the front and append them to a new list. However, the function should not modify the content in the queue. Submit the entire Queue class definition. For example: Test Result car_brand = Queue () Python List: ['Audi', 'Honda', 'Toyota', 'Mercedes'] car_list = ['Audi', 'Honda', 'Toyota', 'Mercedes'l Queue: Front ['Audi', 'Honda', 'Toyota', 'Mercedes'] Rear for item in car_list: car_brand.enqueue (item) print("Python List:", car_brand.to_list()) print(car_brand) Queue: Front ('hello', 'world'] Rear ['hello', 'world', 1] q = Queue () q.enqueue('hello') q.enqueue( 'world') a_list = q.to_list() a_list.append(1) print(q) print(a_list) de gueue: 5 9 Answer: (penalty regime: 0, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50 %) 1 class 2 3 self. items _init__(self): [] def is_empty(self): 6 return self.__items == [] 8 def enqueue(self, item): self.__items. insert(0, item) 10 11 def dequeue(self): . 12 if 'len(self. items) == 0: 13 raise IndexError ("ERROR: The queue is empty!") 14 else: 15 return self.__items.pop() 16 17 def size(self): 18 return len(self.__items) 19 20 def peek(self): if len(self._items) == 0: 22 raise IndexError ("ERROR: The queue is empty!") 23 else: 24 return self.__items[len(self.__items)-1] def len__(self): return len(self.__items) def clear(self): return self.__items.clear() 32 def __str__(self): return "Queue: Front {} Rear".format(self.__items[::-1]) def multi_enqueue(self, element, how_many): for - in 'range (how_many) self.enqueue (element)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!