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.
x.erase(e);
Returns Number of elements removed (0 or 1).
x.Remove(e);
returns true if found and successfully removed, otherwise false.
x.remove(e);
Returns true if value was in the set, and false if not. The method has no effect if value was not in the set.
integer,allocatable::x(:)
integer::e=6
x=[2,4,6,8,10]
!remove 6
x=pack(x,x/=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];
If e was not in x, then nothing happens.
Exclude(x,e);
If e was not in x, then nothing happens.
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
This implementation uses a perl hash %set to act as a set, since keys to a hash must be unique. A list is created to hold the keys, then the hash is initialized from it. The delete operation can delete a specific key. As of version 5.20, you can also delete a hash slice.
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 CPAN Set::Scalar (or Set::Light) to create a set object, which in this example we initialize with letters. We can then use the delete method to delete one or more elements from the set.
@x = grep $e ne $_, @x;
Array is not technically a set since it allows for repeat values. Either you are enforcing uniqueness or you should use a module like Set::Light
x.remove(e)
A KeyError exception is raised if e was already absent.
x.take(e)
x has type mut HashSet
returns Some(e) if the value was present, None otherwise
returns Some(e) if the value was present, None otherwise
x.remove(e);
x has type mut HashSet
returns true if value was present.
returns true if value was present.