1
AutoLISP (Vanilla / Visual) / Re: most common value in a list (mode)
« Last post by ymg on Today at 09:30:34 PM »Just use count items by Lee Mac
Examples:
Code: [Select]
;; Count Items - Lee Mac
;; Returns a list of dotted pairs detailing the number of
;; occurrences of each item in a supplied list.
(defun LM:CountItems ( l / c x )
(if (setq x (car l))
(progn
(setq c (length l)
l (vl-remove x (cdr l))
)
(cons (cons x (- c (length l))) (LM:CountItems l))
)
)
)
Examples:
Code: [Select]
(LM:CountItems '("A" "B" "B" "B" "C" "C" "D" "E" "E" "E" "E"))
=> (("A" . 1) ("B" . 3) ("C" . 2) ("D" . 1) ("E" . 4))
(LM:CountItems '(1 2 3 3 3 4 5 6 6 7 8 8 8 8))
=> ((1 . 1) (2 . 1) (3 . 3) (4 . 1) (5 . 1) (6 . 2) (7 . 1) (8 . 4))