Problem 178079 · easy · Level 01 Prerequisites & Setup

Remove the First Match

lists · remove · membership

Write remove_first(items, target) that returns a new list equal to items with only the first occurrence of target removed. Later occurrences stay. If target is not in the list, return an unchanged copy.

Examples

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

Input:  items = [1, 2], target = 7
Output: [1, 2]

Constraints

  • 0 <= len(items) <= 5000

Goals

  • Remove only the first occurrence of a value
  • Leave the list alone when the value is absent
Starting Python…