MCPcopy
hub / github.com/TheAlgorithms/Python / pop

Method pop

data_structures/stacks/stack.py:57–74  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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 """

Callers 15

infix_to_postfixFunction · 0.95
test_stackFunction · 0.95
balanced_parenthesesFunction · 0.95
collect_datasetFunction · 0.45
astarFunction · 0.45
gradientMethod · 0.45
optimal_merge_patternFunction · 0.45
add_key_to_lexiconFunction · 0.45
build_treeFunction · 0.45
decompress_dataFunction · 0.45

Calls

no outgoing calls

Tested by 2

test_stackFunction · 0.76
breath_first_searchMethod · 0.36