Logo

Programming-Idioms

Remove the element e from the set x.

Explains what happens if e was already absent from x.
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
x.erase(e);
x.remove(e);
integer,allocatable::x(:)
integer::e=6
x=[2,4,6,8,10]
!remove 6
x=pack(x,x/=e)
delete(x, e)
delete(x, e)
import java.util.Set;
x.remove(e);
(defun rmv (elem lst) 
 (if (null lst) nil
   (if (equal elem (car lst)) 
     (cdr lst)
     (cons (car lst) (rmv elem (cdr lst))))) )

(setf x (rmv e x ))
x := x - [e];
Exclude(x,e);
@x = grep $e ne $_, @x;
use strict;
my %set;
my @list = ( 'a' .. 'f' );
$set{$_} = 1 for @list;

delete $set{'c'};	# delete specific key

use v5.20;
delete %set{'a','e'}	# delete hash slice
use strict;
use Set::Scalar;
my $set = Set::Scalar->new( 'a' .. 'f' );

print "Contents of set:\n";
print $set;

$set->delete('b','e');

print "\nAfter removing elements b and e:\n";
print $set;
x.remove(e)
x.delete(e)
use std::collections::HashSet
x.remove(e);
use std::collections::HashSet;
x.take(e)