-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.py
More file actions
43 lines (27 loc) · 724 Bytes
/
Copy pathstack.py
File metadata and controls
43 lines (27 loc) · 724 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from collections import deque
# stack = deque()
# print(dir(stack))
class Stack():
def __init__(self):
self.jar = deque()
def push(self,val):
self.jar.append(val)
def pop(self):
return self.jar.pop()
def peek(self):
return self.jar[-1]
def is_empty(self):
return len(self.jar == 0)
def size(self):
return len(self.jar)
def reverse_string(self):
if type(self.peek()) == str:
return self.peek()[::-1]
else:
raise Exception("Invalid Input")
stack = Stack()
stack.push("hello")
stack.push(2)
stack.push("We will conquere COVID-19")
stack.push(5)
print(stack.reverse_string())