Logo

Programming-Idioms

Remove all occurrences of value x from list items.
This will alter the original list or return a new list, depending on which is more idiomatic.
New implementation

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
(remove #{x} items)
items.remove(x);
using System.Collections.Generic;
items.RemoveAll(r => r == x);
import std.algorithm.iteration;
import std.array;
items = items.filter!(a => a != x).array;
items.removeWhere((y)=>y==x);
Enum.filter(items, fn v -> v != x end)
items = pack (items,items != x)
j := 0
for i, v := range items {
	if v != x {
		items[j] = items[i]
		j++
	}
}
items = items[:j]
j := 0
for i, v := range items {
	if v != x {
		items[j] = items[i]
		j++
	}
}
for k := j; k < len(items); k++ {
	items[k] = nil
}
items = items[:j]
items2 := make([]T, 0, len(items))
for _, v := range items {
	if v != x {
		items2 = append(items2, v)
	}
}
filter (/= x) items
const newlist = items.filter(y => x !== y)
import java.util.Collections;
items.removeAll(Collections.singleton(x));
$newItems = array_diff($items, [$x]);
var
  i: integer;

for i:= items.count-1 downto 0 do
  if items[i] = x then
    items.delete(i);
my @filtered = grep { $x ne $_ } @items;
newlist = [item for item in items if item != x]
items.delete(x)
items = items.into_iter().filter(|&item| item != x).collect();
items.retain(|&item| item != x);
items.filter(_ != x)
items reject: [: y | y = x ]