0
0
DSA Pythonprogramming~15 mins

Dequeue Operation in DSA Python - Build from Scratch

Choose your learning style9 modes available
Dequeue Operation
📖 Scenario: Imagine you are managing a line of customers waiting for service. Sometimes customers leave from the front or the back of the line. You want to keep track of the line and remove customers from either end as needed.
🎯 Goal: You will create a list representing the line of customers, set up a variable to choose which end to remove a customer from, write the code to remove a customer from that end, and finally print the updated line.
📋 What You'll Learn
Create a list called line with these exact customers in order: 'Alice', 'Bob', 'Charlie', 'Diana', 'Ethan'
Create a variable called remove_from_front and set it to True
Write code to remove one customer from the front of the line if remove_from_front is True, otherwise remove one customer from the back
Print the updated line list
💡 Why This Matters
🌍 Real World
Managing lines or queues in places like banks, stores, or amusement parks where people can leave from either end.
💼 Career
Understanding how to manipulate lists and use conditions is important for programming tasks involving queues, stacks, and other data structures.
Progress0 / 4 steps
1
Create the initial line of customers
Create a list called line with these exact customers in order: 'Alice', 'Bob', 'Charlie', 'Diana', 'Ethan'
DSA Python
Hint

Use square brackets to create a list and put the names inside quotes separated by commas.

2
Set the removal direction
Create a variable called remove_from_front and set it to True
DSA Python
Hint

Use the equals sign to assign True to remove_from_front.

3
Remove a customer from the chosen end
Write code to remove one customer from the front of the line if remove_from_front is True, otherwise remove one customer from the back
DSA Python
Hint

Use an if-else statement. Use line.pop(0) to remove from front and line.pop() to remove from back.

4
Print the updated line
Print the updated line list
DSA Python
Hint

Use print(line) to show the updated list.