partial unique?
Posted: Tue Aug 04, 2009 12:44 pm
How can I remove all duplicates from a list except one?
(111222333) becomes (12333) or whatever...
(111222333) becomes (12333) or whatever...
Friends and Fans of newLISP
http://www.newlispfanclub.alh.net/forum/
http://www.newlispfanclub.alh.net/forum/viewtopic.php?f=16&t=2877
Code: Select all
(unique '(2 3 4 4 6 7 8 7)) → (2 3 4 6 7 8)
Code: Select all
(set 'l '("name" "name" "name" "nobody" "nobody" "nobody"))
(set 'keeplist '("nobody"))
(dolist (e l)
(if (find e keeplist)
(push e results -1))
(unless (find e results)
(push e results -1)))
;-> ("name" "nobody" "nobody" "nobody")
Code: Select all
(define (keep? e) (find e '("nobody"))) ;
(append (unique (clean keep? l)) (filter keep? l))