## remove-duplicates and if

Discussion of Common Lisp

### remove-duplicates and if

Hi,

currently I'm facing the following problem and I would be very glad, if anyone could help:
from the following list ((a b c) (a b c) (a b) (a b) (a) (a)) I want to remove all duplicates, except (a b c). The result should be the list ((a b c) (a b c) (a b) (a)).
As this function should operate on the first list, irrespective of the number of (a b c), (a b) or (a).
I tried the function "remove-duplicates", but I don't know how to adapt it so that (a b c) duplicates are not removed.

For any help I would be very grateful!

And please excuse any errors regarding my English...
xvn

Posts: 2
Joined: Thu Dec 05, 2013 1:54 pm

### Re: remove-duplicates and if

Your spec is not complete. Why do you want to keep (A B C) only? Do you want to keep the first? Do you want to keep all the (A B C)? Do you want to remove only the duplicates of length other than 3?

Assuming you want to keep all entries of length equal 3, here is a solution that should give you a hint about other cases"

Code: Select all
`(remove-duplicates '((a b c) (a b c) (a b) (a b) (a) (a))     :test (lambda (x y)             (and (/= (length x) 3)                  (/= (length y) 3)                  (equal x y))))`

Cheers
--
MA
Marco Antoniotti
marcoxa

Posts: 85
Joined: Thu Aug 14, 2008 6:31 pm

### Re: remove-duplicates and if

Perfect, that's exactly what I was looking for! Thanks!
xvn

Posts: 2
Joined: Thu Dec 05, 2013 1:54 pm