Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

stack queue in python

"""
Stack is a Last In First Out Data structure
It can be implemented using a list as illustrated belo
push <==> append, and pop <==> pop from list
"""
stack = ["John", "Elie", "Rami"]
# Push an item
stack.append("Wissam")
print(stack)

# Pop an item: removes the last item
print(stack.pop())

"""
Queue is a First In First Out Data structure
It can be implemented efficiently using a Deque
enqueue <==> append and dequeue <==> popleft
"""
from collections import deque
queue = deque(["Wissam", "John", "Elie"])
queue.append("Rami")
print(queue)

# popleft removes the first element in queue
print(queue.popleft())
Comment

PREVIOUS NEXT
Code Example
Python :: how to find highest number in list without using max function python 
Python :: discord get bot profile picture 
Python :: pyspark now 
Python :: python check if website is reachable 
Python :: cassandra python 
Python :: sort dictionary by value and then key python 
Python :: real hour in python 
Python :: python script as service linux 
Python :: how to install python libraries using pip 
Python :: how to change case of string in python 
Python :: pandas save dataframe to csv in python 
Python :: backtracking python 
Python :: python sns lable axes 
Python :: python int to binary 
Python :: scipy cosine similarity 
Python :: underscore in python 
Python :: vscode set python identation to four 
Python :: end python print with space 
Python :: colors in scatter plot python 
Python :: Calculate Euclidean Distance in Python using norm() 
Python :: django active link 
Python :: .launch.py file in ros2 
Python :: adding proxy in selenium python 
Python :: selenium webdriver scroll down python 
Python :: seaborn iris dataset 
Python :: get dataframe column into a list 
Python :: python argparse lists flags as optional even with required 
Python :: python get the app path 
Python :: declare pandas dataframe with values 
Python :: change item in list python 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =