明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1442|回复: 4

[提问] 有特殊要求的字符串排序

[复制链接]
发表于 2015-3-5 08:34:58 | 显示全部楼层 |阅读模式
本帖最后由 hrbustmqc 于 2015-3-5 08:37 编辑

(("byzm1" "AL1" "单相" "4")
("byzm2" "AL1" "单相" "4")
("cz1" "AL1" "单相" "2")
("cz2" "AL1" "单相" "2")
("fj1" "AL1" "三相" "2")
("fj2" "AL1" "三相" "5")
("fj3" "AL1" "三相" "6")
("fj4" "AL1" "三相" "8")
("kt1" "AL1" "单相" "2")
("qqqqqq1" "AL1" "单相" "2")
("snj1" "AL1" "单相" "2")
("xxxxx1" "AL1" "单相" "2")
("zm1" "AL1" "单相" "1.44")
("zm2" "AL1" "单相" "2")
("zm3" "AL1" "三相" "5")
("普通三相1" "AL1" "三相" "6")
("普通三相2" "AL1" "三相" "12")
("wl2" "AL2" "三相" "2")
("wp2" "AL2" "三相" "4")
("zm3" "AL2" "三相" "2"))
以前提问过,第二项按照AL1 AL2 。。排序, 第三项按照单相、三相排序。承蒙各位指点,已经实现。
现在想让第一项按照指定的字母排序,二三项按AL1 AL2  单相、三相要求排序。
出线的 zm1 zm2  byzm2 byzm2  cz1 cz2  kt1 kt2排在最前面, 第一项出现的其他字母不作要求。

本帖被以下淘专辑推荐:

发表于 2015-3-5 12:01:37 | 显示全部楼层
http://bbs.mjtd.com/thread-113085-1-1.html 9楼
(mapcar '(lambda (f) (setq L (vl-sort L '(lambda (x y) (< (f X) (f Y)))))) (list cadddr caddr cadr car))改一下list后面的几个东西顺序就可以了
 楼主| 发表于 2015-3-6 08:44:50 | 显示全部楼层
自贡黄明儒 发表于 2015-3-5 12:01
http://bbs.mjtd.com/thread-113085-1-1.html 9楼
(mapcar '(lambda (f) (setq L (vl-sort L '(lambda (x  ...

抱歉,这个比较式比较的是什么实在没看懂(< (f X) (f Y)) ,研究了半天,看来我智商拙计!我的意思是其他的排序按照以前的要求,第一项排序  在第一位置的是zm1 zm2 ,排在第二位的是byzm2 byzm2 排在第三位的是 cz1 cz2。希望不吝惜指教。我跑跑程序,看看每步结果就能想的差不多了。
发表于 2015-3-6 14:52:00 | 显示全部楼层
自贡黄明儒 发表于 2015-3-5 12:01
http://bbs.mjtd.com/thread-113085-1-1.html 9楼
(mapcar '(lambda (f) (setq L (vl-sort L '(lambda (x  ...

牛叉 真牛叉!
(list cadddr caddr cadr car)=(list 按倒数第一排 按倒数第二排 按第二排 按第一排序)
((("wl1" "AL1" "单相" "1.44")
   ("wl1" "AL3" "单相" "2")
   ("wl1" "AL2" "单相" "2")
   ("wl2" "AL2" "单相" "2")
   ("wl3" "AL3" "三相" "2")
   ("wl2" "AL1" "单相" "2")
   ("wl3" "AL1" "三相" "5")
)
  (("wl1" "AL1" "单相" "1.44")
    ("wl1" "AL3" "单相" "2")
    ("wl1" "AL2" "单相" "2")
    ("wl2" "AL2" "单相" "2")
    ("wl2" "AL1" "单相" "2")
    ("wl3" "AL3" "三相" "2")
    ("wl3" "AL1" "三相" "5")
  )
  (("wl1" "AL1" "单相" "1.44")
    ("wl2" "AL1" "单相" "2")
    ("wl3" "AL1" "三相" "5")
    ("wl1" "AL2" "单相" "2")
    ("wl2" "AL2" "单相" "2")
    ("wl1" "AL3" "单相" "2")
    ("wl3" "AL3" "三相" "2")
  )
  (("wl1" "AL1" "单相" "1.44")
    ("wl1" "AL2" "单相" "2")
    ("wl1" "AL3" "单相" "2")
    ("wl2" "AL1" "单相" "2")
    ("wl2" "AL2" "单相" "2")
    ("wl3" "AL1" "三相" "5")
    ("wl3" "AL3" "三相" "2")
  )
)
为什么会有这样的效果?
发表于 2015-3-6 15:05:25 | 显示全部楼层
我明白了 解析一下
  1. (mapcar        '(lambda (f)
  2.            (setq L (vl-sort L '(lambda (x y) (< (f X) (f Y)))))
  3.          )
  4.         (list car)
  5. )
相当于:
  1. (setq l (vl-sort L '(lambda (x y) (< (car X) (car Y)))))
刚过完年就看到这么棒的想法,
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-12-27 03:44 , Processed in 0.153641 second(s), 29 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表