Pop an element off of the top of the stack. >>> S = Stack() >>> S.push(-5) >>> S.push(10) >>> S.pop() 10 >>> Stack().pop() Traceback (most recent call last): ... data_structures.stacks.stack.StackUnderflowError
(self)
| 55 | self.stack.append(data) |
| 56 | |
| 57 | def pop(self) -> T: |
| 58 | """ |
| 59 | Pop an element off of the top of the stack. |
| 60 | |
| 61 | >>> S = Stack() |
| 62 | >>> S.push(-5) |
| 63 | >>> S.push(10) |
| 64 | >>> S.pop() |
| 65 | 10 |
| 66 | |
| 67 | >>> Stack().pop() |
| 68 | Traceback (most recent call last): |
| 69 | ... |
| 70 | data_structures.stacks.stack.StackUnderflowError |
| 71 | """ |
| 72 | if not self.stack: |
| 73 | raise StackUnderflowError |
| 74 | return self.stack.pop() |
| 75 | |
| 76 | def peek(self) -> T: |
| 77 | """ |
no outgoing calls