Can someone refresh my memory as to what function is used to remove duplicate strings from a list.
I'm having a brain fart this morning.
Thanks,
Will
|
Can someone refresh my memory as to what function is used to remove duplicate strings from a list.
I'm having a brain fart this morning.
Thanks,
Will
VL-REMOVE would probably be a good choice.
(vl-remove "hey" '("hey" "this" "is" "a" "bunch" "of" "heys"))
("this" "is" "a" "bunch" "of" "heys")
(vl-remove "heys" '("hey" "this" "is" "a" "bunch" "of" "heys"))
("hey" "this" "is" "a" "bunch" "of")
stig,
Thanks for the response. That worked too well I'm afraid.
Let me clarify what I need. I need to delete all the duplicates except one.
list would be :
("hey" "this" "is" "hey" "a" "bunch" "hey" "of" "heys")
remove all "hey" duplicates:
("hey" "this" "is" "a" "bunch" "of" "heys")
Does that clarify it a bit?
Thanks,
Hmmm, it clarifies but also makes it a bit more complex. How is the code supposed to know which item to keep? If the first match is to remain then perhaps something like this will do?
Code:(defun removeAllButFirst (item lst / n ll) (setq n (cdr (member item lst))) (repeat (- (length lst) (length n)) (setq ll (cons (car lst) ll) lst (cdr lst))) (append (reverse ll) (vl-remove item n)) )
I just want it remove all items that are the same except one of them. It doesn't matter which one of them.
Thanks,
I think you want this:
(vl-remove-if predicate-function list)
or:
(vl-remove-if-not predicate-function list)
Ah, no need for order, only removing duplicates:
Ok, so it keeps the first occurrence like the formerCode:(defun removeDups (item lst / ll) (foreach n lst (cond ((equal n item) (and (not (member item ll)) (setq ll (cons n ll)))) (T (setq ll (cons n ll))))) (reverse ll) )
Mark, just being curious: which predicate function would you write for VL-REMOVE-IF to remove duplicates?
Thanks stig I'll work that into my code and see how it works.