Previous Up Next

6.40.9  Removing elements of a list: remove

The remove command removes elements of a list according to a given conditions.


Example.
Input:

remove(x->(x>=2),[0,1,2,3,1,5])

Output:


0,1,1


Remark: You can use remove to remove characters from a string. For example, to remove all the "a"s of a string (see Section 12.1.2 for writing functions):
Input:

orda := ord("a"):;

then:

f(chn):={
local l:=length(chn)-1;
return remove(x->(ord(x)==orda),seq(chn[k],k,0,l));
}

Now:
Input:

f("abracadabra")

Output:


"b","r","c","d","b","r"

To get a string:
Input:

char(ord(["b","r","c","d","b","r"]))

Output:

"brcdbr"

Previous Up Next