Python list.pop
Remove a packing item by position and receive its label as the return value.
A simple example
list.pop
- Start with A, B, C
- Do this Remove the middle item
- Result A, C
Syntax
items.pop(index)
Run these examples in Python
Save one example at a time as lesson.py. Use Python 3.9 or later.
python3 lesson.pyTake a cancelled item off a packing list
A customer cancels the second item on an order after the packing list has printed. The picker uses its position to remove exactly that item and reads the removed label back to the customer.
items = ["Tea", "Soap", "Rice"]
print(items.pop(1))
Soap
pop removes the second item and supplies its label to print.
Prepare the next workshop roster
A teacher reads a workshop roster in arrival order. The middle entry cancels and is removed from the plan. Which two entries still appear, in order?
Work from the delivery round
A courier has three labelled stops in route order. The middle entry cancels and is removed from the plan. Which two entries still appear, in order?
What to watch for
Calling pop without an index removes the final item. An empty list has no item to pop.