[erlang-questions] removing an element from a list

Mazen Harake <>
Tue May 3 11:15:23 CEST 2011


They are equally "good".

A -- [q] says "remove all occurrences found in the right list from the left
list". This is sugar syntax for lists:subtract/2. A -- [q,w] would produce
[e,r,t,y].
lists:delete(q, A) says remote element q from list A (note: only one
element).

The simple answer is: They are almost the same. if you only want to remove 1
element the list then use delete, if you want to remove several then use
subtract.

note: both functions only remove the first occurrence of the element, E.g.
[a,a,b,c] -- [a] will result in [a,b,c] and _not_ [b, c], same behaviour for
delete.

/M

On 3 May 2011 11:04, Ivan Uemlianin <> wrote:

> Dear All
>
> It seems there are two ways to remove an element from a list:
>
>   1> A = [q,w,e,r,t,y].
>   [q,w,e,r,t,y]
>   2> A -- [q].
>   [w,e,r,t,y]
>   3> lists:delete(q, A).
>   [w,e,r,t,y]
>   4>
>
>
> Which is better, and why, or is TMTOWTDI?  (I'm sure the answer won't be as
> simple as the question:).
>
> With thanks and best wishes
>
> Ivan
>
> --
> ============================================================
> Ivan A. Uemlianin
> Speech Technology Research and Development
>
>                    
>                     www.llaisdy.com
>                         llaisdy.wordpress.com
>                     www.linkedin.com/in/ivanuemlianin
>
>    "Froh, froh! Wie seine Sonnen, seine Sonnen fliegen"
>                     (Schiller, Beethoven)
> ============================================================
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110503/65355bb6/attachment.html>


More information about the erlang-questions mailing list