现在我有排序之前将其hastable复制到一个列表:按值排序散列表的最佳方法是什么?
(defun good-red()
(let ((tab (make-hash-table)) (res '()))
(dotimes (i 33) (setf (gethash (+ i 1) tab) 0))
(with-open-file (stream "test.txt")
(loop for line = (read-line stream nil)
until (null line)
do
(setq nums (butlast (str2lst (substring line 6))))
(dolist (n nums) (incf (gethash n tab)))
))
**(maphash #'(lambda (k v) (push (cons k v) res)) tab)**
(setq sort-res (sort res #'< :key #'cdr))
(reverse (nthcdr (- 33 18) (mapcar #'car sort-res)))))
顺便说一句,有什么更好的方式来获取列表的第N个元素?
您的问题是什么?标题中的内容,还是内容中的内容? –
仅仅回答标题中的和/或评论中的那一个,会不会更具有建设性? – Paralife