Hacker Newsnew | past | comments | ask | show | jobs | submit | vatine's commentslogin

OTOH, a more idiomatic version would be (and I would consider using the loop facility to be idiomatic):

  (defun count (pair-list)
    (let ((hash (make-hash-table)))
      (loop for (val key) in pair-list
        do (incf (gethash key hash 0) val))
      (loop for key being the hash-key of hash
        collect (list (gethash key hash) key))))
This drops us from 10 to 7 lines, which is clearly shorter. But, it's also relatively simple to change it from summing a list of (<count> <key>) to a list of (<key> <count>), something that I genuinely can't comment on for the K version. I suspect it would be as simple as first doing a permutation on the input, and (if needed) un-permute the result.


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

Search: