问题
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