Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Challenge: Handling Customer Requests | Efficient Use of Data Structures
Optimization Techniques in Python

book
Challenge: Handling Customer Requests

Tarea

Swipe to start coding

You are tasked with managing a customer support system where customer requests are handled in the order they arrive. However, high-priority requests must be added to the front of the queue. To achieve this:

  1. Initialize the appropriate data structure to maintain the queue of customer requests.
  2. If the required data structure needs to be imported, include the appropriate import statement. Otherwise, remove the import line.
  3. Add regular customer requests to the end of the queue.
  4. Add high-priority customer requests to the front of the queue.
  5. Process requests in the order they should be handled (removing from the front).

Solución

from collections import deque

# Initialize an empty customer support queue
customer_queue = deque()

# Add requests to the end
customer_queue.append('Request 1')
customer_queue.append('Request 2')

# Add a high-priority request to the front
customer_queue.appendleft('High-Priority Request')

# Process requests in the correct order
while customer_queue:
# Remove from the front
current_request = customer_queue.popleft()
print(f"Processing: {current_request}")

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 5
from ___ import ___

# Initialize an empty customer support queue
customer_queue = ___

# Add requests to the end
customer_queue.___('Request 1')
customer_queue.___('Request 2')

# Add a high-priority request tp the front
customer_queue.___('High-Priority Request')

# Process requests in the correct order
while customer_queue:
# Remove from the front
current_request = customer_queue.___()
print(f"Processing: {current_request}")

Pregunte a AI

expand
ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

some-alt