teraz muszę skopiować hastable do listy przed sortowaniem go:Jaki jest najlepszy sposób sortowania hashtable według wartości?
(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)))))
BTW, jaki jest lepszy sposób, aby sprowadzić pierwszych elementów n listy?
Jakie jest twoje pytanie? Ten w tytule lub ten w treści? –
Czy nie byłoby bardziej konstruktywne po prostu odpowiedzieć na pytanie w tytule i/lub w komentarzu? – Paralife