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.

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);
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)

New implementation...