Previous Up Next

5.3.8  Removing elements from a list

Elements can be removed from a list by using either the suppress command (which removes a single element) or the remove command (which removes all elements meeting a given conditions).

Examples

suppress([3,4,2],1)
     

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

0,1,1
          
Remark.

Use remove to remove characters from a string. For example, to remove all the "a"s of a string (see Section 23.1.2 for writing functions):

orda:=ord("a"):;

Then (in a program editor level):

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

Now:

f("abracadabra")
     

“b”,“r”,“c”,“d”,“b”,“r”
          

To get a string:

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

Previous Up Next