combination of pair subsets from a list in lisp

点点圈 提交于 2019-12-13 07:58:10

问题


How to create all possible pairs subsets from a list in conman lisp. For example the list A contain four elements

list A= ("A" "B" "C" "D")  

the expected output is as follows:

(("A","B"),("A","C"), ("A","D"),("B","C"),("B","D"), ("C","D"))

Could someone please help me out to generate these subsets. Thanks a lot


回答1:


Read up on mapcar et al:

(defparameter a (list 1 2 3 4))
(mapcon (lambda (tail)
          (mapcar (lambda (x)
                    (cons (car tail) x))
                  (cdr tail)))
        a)
==> ((1 . 2) (1 . 3) (1 . 4) (2 . 3) (2 . 4) (3 . 4))


来源:https://stackoverflow.com/questions/28942009/combination-of-pair-subsets-from-a-list-in-lisp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!