Jump to content

Recommended Posts

Posted

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

 

Posted (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 by Lee Mac
  • Like 2
  • Thanks 1
Posted (edited)

@Lee Mac

Thanks VERY MATCH

Edited by hosneyalaa

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...