Python: Create a FIFO queue
Python heap queue algorithm: Exercise-28 with Solution
Write a Python program to create a FIFO queue.
Sample Solution:
Python Code:
import queue
q = queue.Queue()
#insert items at the end of the queue
for x in range(4):
q.put(str(x))
#remove items from the head of the queue
while not q.empty():
print(q.get(), end=" ")
print("\n")
Sample Output:
0 1 2 3
Flowchart:
Visualize Python code execution:
The following tool visualize what the computer is doing step-by-step as it executes the said program:
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program to find whether a queue is empty or not.
Next: Write a Python program to create a LIFO queue.What is the difficulty level of this exercise?
Test your Python skills with w3resource's quiz
Python: Tips of the Day
Different ways to test multiple flags at once in Python
Example:
# Different ways to test multiple # flags at once in Python a, b, c = 0, 1, 0 if a == 1 or b == 1 or c == 1: print('passed') if 1 in (a, b, c): print('passed') # These only test for truthiness: if a or b or c: print('passed') if any((a, b, c)): print('passed')
Output:
passed passed passed passed
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- React - JavaScript Library
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework