Version 6 of lrmdups

Updated 2005-03-31 07:21:47 by antirez

Procedure to remove duplicate elements from a list. The returned list will be sorted.

RS: You don't even need a procedure for this, because that's exactly what lsort -unique does:

 interp alias {} lrmdups {} lsort -unique

Testing this interp alias interactively with a tclsh:

 % lrmdups {foo bar grill bar foo}
 bar foo grill

SS: Well.. it depends. lsort -unique does it in O(NlogN), while the trivial algorithm to remove duplicated elements runs in O(N). So if your list is very very long lsort may not be an option. Also you may like to have a stable algorithm that will not alter the order of non-duplicated elements.