(defun same(l1 / l2);;;查找表中重复元素
(while l1 (if (member (car l1) (cdr l1)) (setq l2 (append l2 (list (car l1))))) (setq l1 (vl-remove (car l1) l1)))
l2
)
(defun sametimes(l1);;;;表中重复元素及其重复次数
(mapcar '(lambda(x) (cons x (- (length l1) (length (vl-remove x l1)))))
(same l1))
)
(defun Sametimes(l1 / l2);;;表中重复元素及其重复次数,比前边一个快
(while (setq l2 (if (member (car l1) (cdr l1)) (cons (list (car l1) (- (length l1) (length (vl-remove (car l1) l1)))) l2) l2) l1 (vl-remove (car l1) l1)))
(reverse l2)
)
(defun etimes(l1 / l2);;;所有元素的出现次数
(while (setq l2 (cons (list (car l1) (- (length l1) (length (vl-remove (car l1) l1)))) l2) l1 (vl-remove (car l1) l1)))
l2
)
(defun desame(l1 / l2);;;表中去除重复元素(重复过的不出现)
(last (mapcar '(lambda(x) (setq l1 (vl-remove x l1))) (same l1)))
)
(defun delsame(l1 / l2);;表中去除重复元素(重复过的取第一次出现)
(while (setq l2 (cons (car l1) l2) l1 (vl-remove (car l1) (cdr l1))))
(reverse l2)
)
(defun delsameat(l1 n / l2 a);;;指定几项相同去重,重复时取第一次出现
(if n (setq l1(mapcar'(lambda(x)(cons(mapcar'(lambda(y)(nth y x))n)x))l1)))
(while (setq a (caar l1) l2 (cons (cdar l1) l2) l1 (vl-remove-if '(lambda(x) (equal (car x) a)) (cdr l1))))
(reverse l2)
)
(defun delsame(l1 rcz / l2);;带容差去重(重复过的取第一次出现),有时处理坐标点需要考虑容差
(while l1
(setq l2 (cons(car l1)l2)l1(vl-remove-if'(lambda (x)(equal(car l1)x rcz))(cdr l1))))
(reverse l2)
)
(defun delsame (l1 / L2 X);;重复过的取第一次出现(不带容差)根据自贡黄明儒的修改,只改了写法,所以版权属于自贡黄明儒,转载或者使用此函数请尽可能征得原作者同意并保留以下作者信息)
;by自贡黄明儒
(while (setq x (car l1) l2 (cons x l2) l1 (cdr l1))
(if (member x l1) (setq l1 (vl-remove x l1))))
(reverse l2)
)
(defun delsames(l1 rcz / a l l2);;带容差去重(重复过的不出现),有时处理坐标点需要考虑容差
(while (setq a (car l1) l2 (vl-remove-if '(lambda (x) (<= (distance a x) rcz)) (cdr l1)));;;(equal a x rcz)
(if (= (1+ (length l2)) (length l1)) (setq l (cons a l)))
(setq l1 l2)
)
(if (= (1+ (length l2)) (length l1)) (setq l (cons a l)))
(reverse l)
)
;;;(delsame '((1.00001 2 3) (2 3 4) (1.00002 2.000002 3) (3 4 5)) 0.0001)
;;;((1.00001 2 3) (2 3 4) (3 4 5))
;;;(setq l1'(1 2 3 3 3 5 6 8 8 6))
;;;(SAME l1)
;;;(3 6 8)
;;;(desame l1)
;;;(1 2 5)
;;;;(sametimes '(1 2 2 3 4 5 5 5 5 6 7 8 9 0));;;;((2 . 2) (5 . 4))