Simple function to get duplicates from a list

#1

Hi Om Users

I need a function which gives me the duplicates from my list… like remove-dub but to get the duplicates…
for example
(1 2 3 2 4 3 ) -> (2 3)

is there any existing function?

Thanks a lot
Best
Lena

#2

Dear Lena,

Here something from the net. It is a recursive function. Just copy it in a file named xxx.lisp
and put it in the init folder in your OM app.
the code :
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(in-package :om)

(defun list-dups ( l )
(if l
(if (member (car l) (cdr l))
(cons (car l) (list-dups (remove (car l) (cdr l))))
(list-dups (remove (car l) (cdr l)))
)
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Hope this helps

Best
K

1 Like
#3

Dear Karim

Sry for late reply… thank you for this nice solution!

It works :slightly_smiling_face:

Best
L