Library contents

Python list.pop

Remove a packing item by position and receive its label as the return value.

A simple example

list.pop

  1. Start with A, B, C
  2. Do this Remove the middle item
  3. Result A, C
After removal the next item follows A directly.

Syntax

Python 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.py

Take 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.

From the programitems = ["Tea", "Soap", "Rice"]
ResultSoap
lesson.py
items = ["Tea", "Soap", "Rice"]
print(items.pop(1))
Output
Soap

pop removes the second item and supplies its label to print.

Advertisements

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?

GivenMira · Ivo · Bea
Worked resultMira · Bea

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?

GivenPark · Mill · Pier
Worked resultPark · Pier

What to watch for

Calling pop without an index removes the final item. An empty list has no item to pop.

Documentation for list.pop