我写了一个Clojure函数,可以根据长度频率成功地对列表进行排序。编写Clojure函数根据长度频率对列表进行排序
但是,我不喜欢它的写法。有没有人有任何建议以不同的方式写这篇文章?
(defn lfsort [n]
(let [total (frequencies (map #(count %) n))]
(sort #(< (total (count %1)) (total (count %2))) n)))
(lfsort '((a b c) (d e) (f g h) (d e) (i j k l) (m n) (o)))
((i j k l) (o) (a b c) (f g h) (d e) (d e) (m n))
亲切的问候, 本。
你不喜欢你如何写它?它太慢了,还是有其他原因? – octopusgrabbus