> Erlang中文手册 > delete/2 从列表里面删除一个元素

lists:delete/2

从列表里面删除一个元素

用法:

delete(Element, List) -> List2

内部实现:

%% delete(Item, List) -> List'
%%  Delete the first occurrence of Item from the list L.

-spec delete(Elem, List1) -> List2 when
      Elem :: T,
      List1 :: [T],
      List2 :: [T],
      T :: term().

delete(Item, [Item|Rest]) -> Rest;
delete(Item, [H|Rest]) -> 
    [H|delete(Item, Rest)];
delete(_, []) -> [].

删除列表 List 里的一个元素 Element,只删除第一出现的元素,不会删除相同的元素

lists:delete(a, [a, a, b, c, d]).
lists:delete({3, 4}, [{1, 2}, {3,4}, {5, 6}, {7, 8}, {9, 10}]).