我有一个清单
(("abc" "12" "45")
("abc" "34" "56")
("cdb" "56" "78")
("deg" "90" "67")
("deg" "45" "34"))
期望输出是
(("abc" "12" "45" "34" "56")
("cdb" "56" "78")
("deg" "90" "67" "45 "34)).
在Lisp中,正确的方法是什么?
最佳答案
在一般的口齿不清中,有一种可能是这样的:
(defun merge-lists (lists)
(let ((rv (make-hash-table :test #'equal)))
(mapcar (lambda (list)
(mapcar (lambda (x) (push x (gethash (car list) rv nil))) (cdr list)))
lists)
(loop for key being the hash-keys of rv
collect (cons key (reverse (gethash key rv))))))
关于list - 从列表中删除重复项并将其合并到Lisp中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16574028/