How to remove a list from another list?

How to remove a list from another list?

Anonymous
Not applicable
1,759 Views
5 Replies
Message 1 of 6

How to remove a list from another list?

Anonymous
Not applicable

I have 2 lists.  Each may have multiple occurrances of the same item.  How can I remove one list from another list?

 

For example bigList = {b,b,c,a,c,c,a}

smallList = {b,b,a}

 

I'd like it to return something like {c,c,c,a}

I've tried setDifference, and it almost does what I need. But it removes ALL occurrences of an item, which is a problem.  Preserving order doesn't matter because I'm planning to sort after this.  Ideally it would be rather efficient because each list will have about 20 items, and I'll have to run it about 1000 times.

Reply
Reply
0 Likes
Accepted solutions (1)
1,760 Views
5 Replies
Replies (5)
Message 2 of 6

JackGregory
Alumni
Alumni

We don't have a function for this that I can recall.  The "Set" functions operate essentially as if duplicates can be ignored; the focus is on whether something is in the set or not. 

 

The only solution I can think of is to write a function that iterates over the items in the to-be-removed set, and use position and sublist to find and extract matching items.  But this would not be very efficient.

 

If the lists are big enough, then writing a .Net function and calling it from Intent would be more efficient.

 

It seems like a function removeNth would be a big help here, but I don't recall anyone ever asking for it.

Reply
Reply
0 Likes
Message 3 of 6

Anonymous
Not applicable

Ah. I've been looking for a feature like removeNth() for a few months now (no, I haven't asked until now), but I've always found a workaround.

 

 In .NET what I need to do would be very simple, I'd just use linq.  I'm happy to write a .net function, but how involved is that?  Will the .net function work if I try using this project on ETO server?  I imagine I need a dll, where does it go?  

 

I'll have it working by the time ETO SP1 is released, but it would be really nice if someone would add a removeNth() function. In fact, it would be even nicer if it was introduced as a hotfix long before SP1.

Reply
Reply
0 Likes
Message 4 of 6

JackGregory
Alumni
Alumni

.Net assemblies will get found if they are in the Intent search path.  Generally speaking, if you have an IKS file that references a .Net assembly, you should put the dll in the same place for it to find it when it is demanded.

 

There are a few quirks to directly calling .Net, the most immediately apparent is that you must fully-specify names.  There is no "using" statement.  If you have .Net questions, use a separate thread for them.

 

There is no SP1 or hot fix planned right now.  That doesn't mean there won't be any, just that we don't have any date or anything like that.  The next release is planned for later this year.

Reply
Reply
0 Likes
Message 5 of 6

Anonymous
Not applicable
Accepted solution

Edit: I found it was easier to do in ETO than make a whole new .NET function

 

For anyone else that has this problem, here's what I came up with.  If your goal is to remove a smaller list of items from a larger list, you can loop through each element of the small list and remove one item at a time from the bigger list.  

 

The code is attached as a text file. When it is done, the filteredItems rule will contain all elements from the big list, with the items in the small list removed.  It is built to accept multiples of values.  For example, if the big list contains 3 of an item, and the small list contains 2 of that item, only 2 of the 3 values will be removed from the bigger list.

 

 

Reply
Reply
0 Likes
Message 6 of 6

venkatt
Autodesk
Autodesk

I realize the topic of this discussion is not searching for patterns in a list, but if you'd like to do something like this:

 

Dim InputList As List={"d","a","b","c","a","b","c","a","b","c","a","b","c","a","c"}

Dim PatternList As List={"a","b","c"}

 

Then searching the InputList for PatternList gives these positions where a match occurs:2, 5, 8, 11.

 

A simple but inefficient way traverses all items in InputList and for each item, checks if a pattern match occurs starting from the position of that item - this takes length(InputList) * length(PatternList) time (please see attached PatternMatch_Inefficient.txt for example).

 

A more efficient way uses a failure function for each pattern position so that the search can happen in length(InputList) + length(PatternList) time (please see attached PatternMatch.txt for example).

Reply
Reply
0 Likes