WOLFRAM COMMUNITY
Connect with users of Wolfram technologies to learn, solve problems and share ideas
Join
Sign In
Dashboard
Groups
People
Message Boards
Answer
(
Unmark
)
Mark as an Answer
WOLFRAM COMMUNITY
Dashboard
Groups
People
0
|
6483 Views
|
5 Replies
|
1 Total Likes
View groups...
Follow this post
Share
Share this post:
GROUPS:
Mathematica
Very simple question with MemberQ
Seokin Yeh
Seokin Yeh, Heritage High School
Posted
12 years ago
I want to make a function that will take list A, match it with list B, and delete any non-matching elements in list A.
I imagine that this will be very easy to accomplish using MemberQ, however, I cannot think up a way.
Help,
POSTED BY:
Seokin Yeh
Reply
|
Flag
5 Replies
Sort By:
Replies
Likes
Recent
0
Rodrigo Murta
Rodrigo Murta, Looqbox
Posted
12 years ago
Maybe
this SE post
can help.
POSTED BY:
Rodrigo Murta
Reply
|
Flag
0
Youngjoo Chung
Youngjoo Chung, GIST
Posted
12 years ago
The pure function
!MemberQ[B, #] &
is applied to each element (#) of A. In the above example, it will be a, b, c, d.
POSTED BY:
Youngjoo Chung
Reply
|
Flag
0
Seokin Yeh
Seokin Yeh, Heritage High School
Posted
12 years ago
Thank you, however a quick question.
Which variable is the pure fuction taking as #?
POSTED BY:
Seokin Yeh
Reply
|
Flag
1
Ilian Gachevski
Ilian Gachevski, Wolfram Research
Posted
12 years ago
Depending on the exact usage and how repeated elements should be treated, functions like Complement and DeleteCases might also be helpful. Take a look at this
thread
for some interesting examples.
POSTED BY:
Ilian Gachevski
Reply
|
Flag
0
Youngjoo Chung
Youngjoo Chung, GIST
Posted
12 years ago
Hi,
Try the following:
fun[A_List, B_List] := Select[A, ! MemberQ[B, #] &];
fun[{a, b, c, d}, {c, d, e, f}]
Out[]= {a, b}
Youngjoo Chung
POSTED BY:
Youngjoo Chung
Reply
|
Flag
Reply to this discussion
in reply to
Add Notebook
Community posts can be styled and formatted using the
Markdown syntax
.
Tag limit exceeded
Note: Only the first five people you tag will receive an email notification; the other tagged names will appear as links to their profiles.
Publish anyway
Cancel
Reply Preview
Attachments
Remove
Add a file to this post
Follow this discussion
or
Discard
Group Abstract
Be respectful. Review our
Community Guidelines
to understand your role and responsibilities.
Community Terms of Use
Feedback
Enable JavaScript to interact with content and submit forms on Wolfram websites.
Learn how »