I am trying to implement a stack, then use a module called reverse_list to add something to the stack using a prebuild push module within the stack class, and then pop it out of the stack in to a list, then add it back to the stack and return it. But when i run the function it looks like the items do not get properly added to the property self.items, as the debugger shows that it forever remains at "[]", which is not a desired result, which also means it skips the other functions that require the list to be anything but empty.
my_list = [1, 2, 3, 4, 5]
class Stack:
def __init__(self):
self.items = []
def push(self, item):
if type(item) == list or type(item) == tuple:
for items in item:
self.items.append(items)
else:
self.items.append(item)
def pop(self):
self.items.pop()
def reverse_list(self, arr):
classer = Stack()
classer.push(my_list)
temp_list = []
while self.items:
temp_list.append(self.items.pop())
for elements in temp_list:
self.items.append(elements)
return self.items
if __name__ == "__main__":
starter = Stack()
print(starter.reverse_list(my_list))
Current output: []
Desired output: [5, 4, 3, 2, 1]
Danke