return str.join(s, [nested_join(s, x) if isinstance(x, list) else x for x in L])
Empty Stack: (last in, first out)
After Pushing
A, you get:
After Pushing
B, you get:
After Popping, you get:
class Stack:
"""A last-in, first-out (LIFO) stack of items"""
def __init__(self: 'Stack', data: list =None) -> None:
"""Create a new empty Stack using data
data --- initial contents of Stack
"""
if data:
self._data = data[:]
else:
self._data = []
def pop(self: 'Stack') -> object:
"""Remove and return the top item."""
return self._data.pop()
def is_empty(self: 'Stack') -> bool:
"""Return whether the stack is empty."""
return self._data == []
def push(self: 'Stack', obj: object) -> None:
"""Place o on top of the stack."""
self._data.append(obj)
|
没有评论:
发表评论