Remove Specified Item

Remove Specified Item

Tags: Data Structures Basics

Credit: CodingChallenge

Difficulty: Beginner

Type: Text

Category: Practice

Time Allowed: 5 s

Description:

Write a function that takes a list and a value, and returns a new list with all occurrences of the specified value removed. This problem is designed to help you practice removing items from lists. The function should accept two parameters and return the modified list.

Constraints:

  • The first input will be a list of elements.
  • The second input can be any data type that may be in the list.
  • The function should return a list with all occurrences of the specified value removed.
  • Do not modify the original list; create a new list.

Example:

  • Input: [1, 2, 3, 2, 4], 2
  • Output: [1, 3, 4]

Test Case Input Expected Output
1 [[1, 2, 3, 2, 4], 2] [1, 3, 4]
2 [[5, 5, 5, 5], 5] []
3 [[], 1] []
4 [[1, 2, 3], 4] [1, 2, 3]
5 [[True, False, True], True] [False]
6 [['a', 'b', 'a', 'c'], 'a'] ['b', 'c']
7 [[1, 2, 3, 4, 5], 3] [1, 2, 4, 5]

Please register or login to submit solutions to challenges.