kulfi 发表于 2022-7-6 07:44:16

列出内容

确切地说,这就是我需要列表1=((0 0)(1 0.1)(2 0.1)(3 0.1)(4 0.2)(5 0.2)(6 0.3)(7 0.3))的方式。首先,上面给出的列表每次都会变化。其次,我想为相同的cdr元素分离列表,并将它们存储到我想要的变量中
列表A=(0 0)
列表B=(1 0.1)(2 0.1)(3 0.1)
列表C=。。。。。。。。。。。。。。。。。。。。。。。。。。。。等
谢谢
 
 

 
 
 
如果我得到这样一个列表也很好
列表1((0.0)(1.1)(4.2)(6.3))

Tharwat 发表于 2022-7-6 08:38:26

这里有许多回复你的线程是相同的线程标题和内容以及。
 
http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/List-Conents/td-p/3532496

Lee Mac 发表于 2022-7-6 09:11:55

考虑以下功能:
 

;; Group By Function-Lee Mac
;; Groups items considered equal by a given predicate function

(defun LM:GroupByFunction ( lst fun / tmp1 tmp2 x1 )
   (if (setq x1 (car lst))
       (progn
         (foreach x2 (cdr lst)
               (if (fun x1 x2)
                   (setq tmp1 (cons x2 tmp1))
                   (setq tmp2 (cons x2 tmp2))
               )
         )
         (cons (cons x1 (reverse tmp1)) (LM:GroupByFunction (reverse tmp2) fun))
       )
   )
)

 
使用适当的谓词函数调用上述函数:
 
(LM:GroupByFunction
'(
       (0 0)
       (1 0.1)
       (2 0.1)
       (3 0.1)
       (4 0.2)
       (5 0.2)
       (6 0.3)
       (7 0.3)
   )
   (lambda ( a b ) (= (cadr a) (cadr b)))
)

Returns:
(
   ((0 0))
   ((1 0.1) (2 0.1) (3 0.1))
   ((4 0.2) (5 0.2))
   ((6 0.3) (7 0.3))
)
页: [1]
查看完整版本: 列出内容