我如何在 Lisp 中找到一个列表有多少个不同的元素?
(length (remove-duplicates <your list>))
The shortest way of doing it, but it is also possible to do it in a single pass, like so:
(defun count-distinct (list)
(let ((table (make-hash-table)))
(dolist (i list (hash-table-count table))
(setf (gethash i table) t))))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.