I am trying to figure out how to get a list of items that are in one list, but not in another list. Since I am dealing with a very long lists going through and checking each line and matching things up is very time consuming, and I am trying to find a faster way.
What I really want is something that works like intersect array, but instead of discarding the non-matching items, I just want that list of non-matching items.
Any way to do something like this (or just anything that is fast than what I am doing right now, which involves for each-ing through one of the variables...
The opposite of intersect array?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
The opposite of intersect array?
Last edited by edgore on Wed Aug 07, 2013 1:22 am, edited 1 time in total.
Re: The opposite of intersect array?
Hi Ed,
could you give an example of the list and the items, what exactly are the criteria, what defines a non-matching item. An item (in the Livecode sense) or what? Or do you want to test for non-identical lines?
Best would be an example of a matching line and a non-matching line.
Kind regards
Bernd
could you give an example of the list and the items, what exactly are the criteria, what defines a non-matching item. An item (in the Livecode sense) or what? Or do you want to test for non-identical lines?
Best would be an example of a matching line and a non-matching line.
Kind regards
Bernd
Re: The opposite of intersect array?
Here is an example
I have one with one item per line (currently they are all numbers, but that might not always be true in the future.
Let's say the list is:
1234567
1234568
1234569
1234560
1234561
I have another list that contains, say:
1234567,value one,123-1234
1234568,value two,345-4567
1234569,value one,765-4567
1234560,value three,765-8664
I want the result of the operation (which is basically the equivalent of an SQL "except" operation) to be:
1234561
Basically, the one line from the first list that doesn't appear in the second list.
I don't care about retaining any values in the second list, so I could do a split on the second list by comma and get back the keys of the array that created to make a list of just the first items if needed. I know that I could do this by popping everything in database tables and actually doing a select except, but for various reasons (multi-user server environment, desire to not create and drop a bunch of tables, or sqllite files) I would prefer to handle this in a script if it's possible. It surprised me that I could do a union or a intersect of the keys of arrays, but not an except....
I have one with one item per line (currently they are all numbers, but that might not always be true in the future.
Let's say the list is:
1234567
1234568
1234569
1234560
1234561
I have another list that contains, say:
1234567,value one,123-1234
1234568,value two,345-4567
1234569,value one,765-4567
1234560,value three,765-8664
I want the result of the operation (which is basically the equivalent of an SQL "except" operation) to be:
1234561
Basically, the one line from the first list that doesn't appear in the second list.
I don't care about retaining any values in the second list, so I could do a split on the second list by comma and get back the keys of the array that created to make a list of just the first items if needed. I know that I could do this by popping everything in database tables and actually doing a select except, but for various reasons (multi-user server environment, desire to not create and drop a bunch of tables, or sqllite files) I would prefer to handle this in a script if it's possible. It surprised me that I could do a union or a intersect of the keys of arrays, but not an except....
Re: The opposite of intersect array?
edgore --
Here's one way.
-- Dick
Here's one way.
-- Dick
Code: Select all
split tList1 by cr as set
repeat for each line tLine in tList2
delete variable tList1[ item 1 of tLine ]
end repeat
combine tList1 by cr as set
Re: The opposite of intersect array?
Yep - that works, and it's very fast! I had run into so many problems with the other "for each" based methods (they were all very slow) that it would never have occurred to me that deleting keys was a very fast option! Have to remember from now on - try every array based way you can of doing something first, it's going to be the fastest.