Jump to content

Retrieve a list based on another list


RepCad

Recommended Posts

Hello everyone,

I have a list of some numbers as text, for example : (it may has just one item)

("304" "352" "361")

 

and there is another list which it has  lots of members and it's sort based on first element like this

(("301" x y) ("304" x y) ("327" x y)  ("331" x y) ("347" x y) ("352" x y) ("359" x y) ("361" x y))

 

Finally I want to retrieve this list from the two lists : (I mean each element of the first list should be search in the second list, if it's equal, the list is retrieved from the second list)

(("304" x y) ("352" x y) ("361" x y))

 

Can someone give the fastest way to perform it ? 

Thanks in advance

 

 

Edited by amir0914
Link to comment
Share on other sites

(foreach str '("304" "352" "361")
  (if (setq ass (assoc str '(("301" x y) ("304" x y) ("327" x y)  ("331" x y) ("347" x y) ("352" x y) ("359" x y) ("361" x y))))
    (setq grp (cons ass grp))
    )
  )

 

  • Like 1
Link to comment
Share on other sites

Another -

(setq l1 '(("301" x y) ("304" x y) ("327" x y)  ("331" x y) ("347" x y) ("352" x y) ("359" x y) ("361" x y))
      l2 '("304" "352" "361")
)
(vl-remove-if-not '(lambda ( x ) (member (car x) l2)) l1)

 

  • Like 1
Link to comment
Share on other sites

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...