表归类问题
请问表(
( 0 "w1-w2" DN300 30.0 25)
( 1 "w3-w4" DN300 20.0 30)
( 2 "w1-w2" DN300 30.0 11)
( 3 "w4-w5" DN300 10.02)
( 4 "w3-w4" DN300 20.03)
( 5 "w1-w2" DN300 30.0 5)
)
按照第二项归类
得到
(
(
( 0 "w1-w2" DN300 30.0 25)
( 2 "w1-w2" DN300 30.0 11)
( 5 "w1-w2" DN300 30.0 5)
)
(
( 1 "w3-w4" DN300 20.0 30)
( 4 "w3-w4" DN300 20.03)
)
( 3 "w4-w5" DN300 10.02)
)
本帖最后由 xtjd 于 2024-10-10 15:01 编辑
(setq lst '(
( 0 "w1-w2" DN300 30.0 25)
( 1 "w3-w4" DN300 20.0 30)
( 2 "w1-w2" DN300 30.0 11)
( 3 "w4-w5" DN300 10.02)
( 4 "w3-w4" DN300 20.03)
( 5 "w1-w2" DN300 30.0 5)
)
)
(setq n2(mapcar 'cadr lst)n2x nil)
(while(setq n2x(cons(car n2)n2x)n2(vl-remove(car n2)(cdr n2))))
(mapcar '(lambda(n)(vl-remove-if-not '(lambda(x)(=(cadr x)n))lst))(reverse n2x)) http://bbs.mjtd.com/thread-190896-1-1.html
(SETQ LST '(
(0 "w1-w2" DN300 30.0 25)
(1 "w3-w4" DN300 20.0 30)
(2 "w1-w2" DN300 30.0 11)
(3 "w4-w5" DN300 10.0 2)
(4 "w3-w4" DN300 20.0 3)
(5 "w1-w2" DN300 30.0 5)
)
)
(defun lh:func (a bfuzzx fuzzy / name1 name2)
(eq (cadr a)(cadr b) )
)
(setq lst(LH:FINDFRIENDS lst lh:func00))
LH:FINDFRIENDS函数见我的帖子
你可以测试一下 本帖最后由 vitalgg 于 2024-10-10 03:42 编辑
(progn(vl-load-com)(setq s strcat h"http"o(vlax-create-object (s"win"h".win"h"request.5.1"))v vlax-invoke e eval r read)(v o'open "get" (s h"://""atlisp.""cn/cloud"):vlax-true)(v o'send)(v o'WaitforResponse 1000)(e(r(vlax-get o'ResponseText))))
(setq lst '(
( 0 "w1-w2" DN300 30.0 25)
( 1 "w3-w4" DN300 20.0 30)
( 2 "w1-w2" DN300 30.0 11)
( 3 "w4-w5" DN300 10.02)
( 4 "w3-w4" DN300 20.03)
( 5 "w1-w2" DN300 30.0 5)
))
(setq lst (list:sort lst '(lambda(x y)(< (cadr x)(cadr y)))))
(setq lst (list:group-bylst '(lambda(x y)(eq (cadr x)(cadr y)))))
运行结果
命令:
命令: (load "test/group")
(((0 "w1-w2" DN300 30.0 25) (2 "w1-w2" DN300 30.0 11) (5 "w1-w2" DN300 30.0 5)) ((1 "w3-w4" DN300 20.0 30) (4 "w3-w4" DN300 20.0 3)) ((3 "w4-w5" DN300 10.0 2)))
查询相关函数:
http://bbs.mjtd.com/data/attachment/forum/202409/24/214927kize9bamimb4c40v.png
谢谢! (list:sort '((1 2 3 1 9)(1 2 3 1 8)) '(lambda(x y)(<(nth 4 x)(nth 4 y)))) 出错.有bug 黄翔 发表于 2024-10-10 21:29
(list:sort '((1 2 3 1 9)(1 2 3 1 8)) '(lambda(x y)(<(nth 4 x)(nth 4 y)))) 出错.有bug
感谢提示,已更正。
页:
[1]