Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #277 Remove an element from a set

Remove the element e from the set x.

Explains what happens if e was already absent from x.

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;
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
@x = grep $e ne $_, @x;
(disj x e)
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)
x.delete(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.remove(e)
x.delete(e)
use std::collections::HashSet
x.remove(e);
use std::collections::HashSet;
x.take(e)

New implementation...