【发布时间】:2011-11-22 10:25:03
【问题描述】:
现在我必须在排序之前将 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 个元素的更好方法是什么?
【问题讨论】:
-
你有什么问题?是标题中的那个,还是内容中的那个?
-
只回答标题中的那个和/或 cmets 中的那个不是更有建设性吗?