hosneyalaa Posted August 31, 2023 Share Posted August 31, 2023 HI Everyone , Question please How can an sort as in the example? I have a list (setq lst '(("dwgmodels.com" "10006" 1 "") ("dwgmodels.com" "10005" 10 "") ("dwgmodels.com" "10004" 7 "") ("dwgmodels.com" "10003" 3 "") ("dwgmodels.com" "10002" 4 "") ("dwgmodels.com" "10001" 4 ""))) And another list (setq dsd '(10008 10006 10002 10001 10005 10007 10003 10004) ) I want SORT lst LIST Dependence on dsd LIST the result (setq lstret '(("dwgmodels.com" "10006" 1 "") ("dwgmodels.com" "10002" 4 "") ("dwgmodels.com" "10001" 4 "") ("dwgmodels.com" "10005" 10 "") ("dwgmodels.com" "10003" 3 "") ("dwgmodels.com" "10004" 7 ""))) Thanks in advance Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 31, 2023 Share Posted August 31, 2023 (edited) Here's one possible way - (vl-sort lst '(lambda ( a b ) (< (vl-position (atoi (cadr a)) dsd) (vl-position (atoi (cadr b)) dsd)))) Or, perhaps faster: (mapcar '(lambda ( n ) (nth n lst)) (vl-sort-i (mapcar '(lambda ( x ) (vl-position (atoi (cadr x)) dsd)) lst) '<)) Or, if you only want members that are present in dsd, you could use - (vl-remove nil (mapcar '(lambda ( x ) (car (vl-member-if '(lambda ( y ) (= x (atoi (cadr y)))) lst))) dsd)) Edited August 31, 2023 by Lee Mac 2 1 Quote Link to comment Share on other sites More sharing options...
hosneyalaa Posted August 31, 2023 Author Share Posted August 31, 2023 (edited) @Lee Mac Thanks VERY MATCH Edited August 31, 2023 by hosneyalaa Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.