Problem 155654 · easy · Level 01 Prerequisites & Setup

All Positions of a Value

lists · searching · enumerate

Write all_positions(items, target) that returns a list of every index at which target appears in items, in increasing order. Return an empty list if it never appears.

Examples

Input:  items = [2, 7, 2, 9, 2], target = 2
Output: [0, 2, 4]

Input:  items = [1, 2, 3], target = 5
Output: []

Constraints

  • 0 <= len(items) <= 5000

Goals

  • Collect every index where a value appears
  • Use enumerate or range to track indexes
Starting Python…