Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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)))


As much as Lisp isn't meant for code golf, I think the loop variation could be used as a (rather long) one-liner.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: