-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack.py
More file actions
30 lines (23 loc) · 861 Bytes
/
Copy pathStack.py
File metadata and controls
30 lines (23 loc) · 861 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
class Stack:
def __init__(self):
"""__init__ is used to establish baseline of calss for each instantiation"""
self.items = []
def push(self, item):
"""take the item passed as an argument and append to end of list"""
self.items.append(item)
def pop(self):
"""return and Remove the last element from the Stack, items does this natively"""
if self.items:
return self.items.pop()
return None
def peek(self):
"""look at the last item on the stack, without removing"""
if self.items:
return self.items[-1]
return None
def size(self):
"""Return the length of the stack"""
return len(self.items)
def is_empty(self):
"""Return true or false if there are any items in the list"""
return self.items == []