|
Background
I'm attempting to solve a problem in the most efficient way possible.
Attempting to solve the problem put me on the path to attempting to explain the problem.
That put me on the path of wondering if there is a term for this.
Problem Definition
I have two lists of strings.
* origItems
* newItems
I want to find all the strings in newItems that are not contained in origItems.
I want to make a new list that contains only those new items.
The C# code to solve the problem looks like the following:
List<String> origItems = new List<String>();
origItems.Add("abc");
origItems.Add("def");
origItems.Add("ghi");
List<String> newItems = new List<String>();
newItems.Add("abc");
newItems.Add("def");
newItems.Add("super");
newItems.Add("extra");
List<String> itemsOnlyInNew = newItems.Except(origItems).ToList();
foreach (String s in itemsOnlyInNew){
Console.WriteLine(s);
}
The output is :
super
extra
Is there a mathematical term that covers this (searching one list based upon another list of items)?
(I'm thinking like the term permutation but I don't believe this is a permutation.)
Please Feel Free To Make Up A Term
If there isn't already a term (in English), please make one up.
If there is a term in another language please share that and we'll incorporate it.
Just thought this was interesting.
Thanks much.
|
|
|
|
|
Isn't it set theory: newItems - origItems?
Think of the two sets as a Venn Diagram, intersection, union, etc.
|
|
|
|
|
NeverJustHere wrote: Think of the two sets as a Venn Diagram, intersection, union, etc.
After posting. I got up. Walked out to make coffee and was talking to the wife unit when that hit me.
Sometimes I just post dumb questions. Oops.
|
|
|
|
|
I just missed that you answered already with set theory. Was not my intention to plagiarize
|
|
|
|
|
|
After posting. I got up. Walked out to make coffee and was talking to the wife unit when that hit me. Blush |
Thank you for your informative and kind answer.
I think I must've been thinking of the specific instance and related code so much I confused my simple brain. I'm kinda dumb sometimes.
|
|
|
|
|
Don't worry, happens to me nearly everyday and sometimes (usually?) more than one time per day
|
|
|
|
|
Thank you
I'm crawling under my desk for while.
|
|
|
|
|
No need Or then I also have to do it.
A customer send me the information the angle is 390 deegree.
I was that much confused and answered this can't be possible. On the other hand I have no problem when somebody tells me the angle is 2.5 π rad whatelse
|
|
|
|
|
Are duplicates possible? (Not that it really matters.)
|
|
|
|
|
Thanks for your question. Duplicates in orig and new are possible.
Duplicates in final set are not allowed.
|
|
|
|
|
|
I agree with the previous posters: Set Theory
In C++ there is the container std::set something similar exists in Python so I assume C# also has something like it.
In C++ it looks like this:
set_difference - C++ Reference[^]
"If we don't change direction, we'll end up where we're going"
|
|
|
|
|
In Set Theory, the opposite of "Intersection" is "Difference". You're describing a Difference operation.
|
|
|
|
|
Be careful on order if you use a library.
A.diff(B) != B.diff(A)
I have seen Difference used for this operation.
It looks like Complement could be another term.
There is also Symmetric Difference which contains outliers from both sets.
|
|
|
|
|
OK, not a Maths term per se, but when anyone invokes the 'M' word in my hearing I always think "Freudenschade"......
|
|
|
|
|
|
In case it might be useful to you.
I have ubuntu Linux running on my Win 10 laptop (WSL) and it has this handy program called comm. I use it when I need to do a task like you describe. HTH
Usage: comm [OPTION]... FILE1 FILE2
Compare sorted files FILE1 and FILE2 line by line.
When FILE1 or FILE2 (not both) is -, read standard input.
With no options, produce three-column output. Column one contains
lines unique to FILE1, column two contains lines unique to FILE2,
and column three contains lines common to both files.
|
|
|
|
|
|
R.I.P. I liked some of his stuff, but definitely talented.
The less you need, the more you have.
Even a blind squirrel gets a nut...occasionally.
JaxCoder.com
|
|
|
|
|
I finished GTAV DLC "The Contract" - which has been a bugbear for me as it crashed at the end of three missions several times. Got there in the end though. Quite a fun one!
And ... drum roll please ... I'm cooking a fish curry for supper tonight, so I just cut a Cod loin in half - half for Herself, half for me. Cutting by eye, I them weighed the pieces. 134g for the first one, and ... 133g for the second. Nice. That's a small but good triumph, I don't normally estimate it that close!
Probably never get quite that close again, either.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Fish should be eaten raw (or breaded and deep fried).
|
|
|
|
|
Yep. Speckled Trout in New Orleans. I have had Cod before, and it was OK, but a little too bland for my tastes. Don't know how it is in a curry.
But that's what makes horse races. You go Griff!.
Spicy in NOLA
|
|
|
|
|
I was reading that post and thought to myself - there but for the brace of cod go I.
|
|
|
|
|
Boom-Tish!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|