- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a list of lists I would like to sort by two entries. I once had a need to do a sort and the forum helped a lot. So, I thought I would ask again. I thought I would first attempt the code I was once given and as I was studying how it worked and how I could use it, I found that vl-sort will remove duplicate items. And then someone posted code in CADTutor that Kent1Cooper had wrote using mapcar to retain the duplicates. His code is slightly above my abilities.
My list is:
(setq LST
'(((1 . "T1") (2 . "l-cre-non.dwg") (3 . 4) (4 . "CREPE MYRTLE") (5 . 8) (6 . 1))
((1 . "T2") (2 . "l-mag-non.dwg") (3 . 12) (4 . "MAGNOLIA") (5 . 24) (6 . 1))
((1 . "T3") (2 . "l-oak-non.dwg") (3 . 10) (4 . "OAK") (5 . 20) (6 . 1))
((1 . "T4") (2 . "l-app-non.dwg") (3 . 12) (4 . "APPLE") (5 . 24) (6 . 1))
((1 . "T5") (2 . "l-app-non.dwg") (3 . 8) (4 . "APPLE") (5 . 16) (6 . 2))
))
I would like to first sort by association 4 (cdr (assoc 4 LST)), then by association 3 (cdr (assoc 3 LST))
The list should be returned as:
(setq LST
'(((1 . "T5") (2 . "l-app-non.dwg") (3 . 8) (4 . "APPLE") (5 . 16) (6 . 2))
((1 . "T4") (2 . "l-app-non.dwg") (3 . 12) (4 . "APPLE") (5 . 24) (6 . 1))
((1 . "T1") (2 . "l-cre-non.dwg") (3 . 4) (4 . "CREPE MYRTLE") (5 . 8) (6 . 1))
((1 . "T2") (2 . "l-mag-non.dwg") (3 . 12) (4 . "MAGNOLIA") (5 . 24) (6 . 1))
((1 . "T3") (2 . "l-oak-non.dwg") (3 . 10) (4 . "OAK") (5 . 20) (6 . 1))
))
I would appreciate any help given. Thanks.
Windows 10 Pro, x64, Nvidia Quadro P1000
Intel Core i9-11900k; 3.50GHz, 32 GB RAM, 500GB WD BLACK M.2
Solved! Go to Solution.