Stack

Defining a Stack

  • A stack is a collection that:

    • Is indexed
    • Allows duplicates
    • Is linear
    • Is LIFO

Creating a Stack

>>> fruits = ['apple', 'banana', 'pear']
>>> print(fruits)
['apple', 'banana', 'pear']

Adding to a Stack

>>> fruits = ['apple', 'banana', 'pear']
>>> fruits.append('banana')
>>> print(fruits)
['apple', 'banana', 'pear', 'banana']

Removing from a Stack

>>> fruits = ['apple', 'banana', 'pear']
>>> fruits.pop()
>>> 'pear'
>>> print(fruits)
['apple', 'banana']

References

Previous
Next

Dictionary

Enum