[erlang-questions] removing an element from a list
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
lists:delete(q, A) says remote element q from list A (note: only one
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
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
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].
> 2> A -- [q].
> 3> lists:delete(q, A).
> 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 A. Uemlianin
> Speech Technology Research and Development
> "Froh, froh! Wie seine Sonnen, seine Sonnen fliegen"
> (Schiller, Beethoven)
> erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions