-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path4. Stack.py
More file actions
43 lines (28 loc) · 748 Bytes
/
Copy path4. Stack.py
File metadata and controls
43 lines (28 loc) · 748 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
43
from collections import deque
class Stack:
def __init__(self):
self.container = deque()
def push(self,value):
self.container.append(value)
def pop(self):
return self.container.pop()
def peek(self):
return self.container[-1]
def is_empty(self):
return len(self.container) == 0
def size(self):
return len(self.container)
def __repr__(self):
return '{}'.format(self.container)
if __name__ == '__main__':
stack = Stack()
stack.push(5)
print(stack.peek())
print(stack.pop())
print(stack)
print(stack.is_empty())
stack.push(67)
stack.push(7)
stack.push(748)
print(stack.size())
print(stack)