3 ms·
Now you have me thinking about how short I can make that. My revision: (defun doit (elts) (mapcar (lambda (elt) `(,(count elt elts :test 'equal :k
by SeanLuke 3y ago
Now you have me thinking about how short I can make that. My revision:
(defun doit (elts)
(mapcar (lambda (elt) `(,(count elt elts :test 'equal :key 'second) ,elt))
(delete-duplicates (mapcar 'second elts) :test 'equal)))))
or maybe
(defun doit (elts)
(loop for elt in (delete-duplicates (mapcar 'second elts) :test 'equal)
collect `(,(count elt elts :test 'equal :key 'second) ,elt)))
- tmtvl 3y agoAs much as Lisp isn't meant for code golf, I think the loop variation could be used as a (rather long) one-liner.