Jump to content

Is there a way to iterate over multiple lists to delete a duplicate element?


Gayngel
 Share

You are about to reply to a thread that has been inactive for 1356 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Is there a UDF somewhere that can iterate over multiple lists and delete duplicate elements and keep the element in just one list? (sort of like the .zip()function in Python) 

e.g:

list a = ["Apples"];

list b = ["Apples"];

list c = ["Apples"];

 

if the element "Apples" in list a is also in list b and list c delete it from both list b and c.

Link to comment
Share on other sites

You can add JSON constructs to lists to give you the same as a multi array. You said you want to compare lists against other lists is this all you are trying to do llListFindList will find a list item in a list if its an exact match you will have to parse one list with two others and then second with third. If its a partial match then you need a script:

//************************************ CORE ROUTINES BELOW WERE LSL LACKS FUNCTIONS **Virtual Kitten
integer _contains(string haystack, string needle) 
{
    return ~llSubStringIndex(haystack, needle);
}
integer _llStringPartialFindList(list list_1, string string_1) {
    integer s1 = llGetListLength(list_1);
    integer s2 = llGetListLength(list_1);
    integer  n;
    for(n=0;n<s2;n++) { 
     if (_contains(llList2String(list_1,n) ,string_1)!=0) return n;
    }
    return -1;
}

Link to comment
Share on other sites

the method depends on what the desired outcome is:

for example, given the following:

list a = ["apple","banana","carrot"];
list b = ["apple","banana"];
list c = ["carrot"];

is 7 possible outcomes

a = ["apple","banana","carrot"]; b = []; c = [];
a = ["apple","banana"]; b = []; c = ["carrot"];
a = ["apple"]; b = ["banana"]; c = ["carrot"];
a = ["banana","carrot"]; b = ["apple"]; c = [];
a = ["banana"]; b = ["apple"]; c = [carrot];
a = ["carrot"]; b = ["apple","banana"]; c = [];
a = []; b = ["apple","banana"]; c = ["carrot"];

each outcome depends on the order in which the lists are presented, and any other rules of precedence we might determine/code for our particular app use case

 

Link to comment
Share on other sites

A user function probably exists somewhere, but the gist of the process is... Take each item from List A one by one and llListFIndList() for that item in List B. If found, remove and if it’s possible to have duplicates in the same list, scan List B again. Else, scan List C. Repeat with item two.

After running through all items in List A, do the same with List B, but only llListFindList() in List C, since you already know there are no copies in List A.

No need to process items in List C, or whatever is the last list, since its dupes would’ve been found in scans from previous lists.

Probably best to start with the smallest list first, working towards the largest which, hopefully, won’t need to be processed at all.

Edited by DoteDote Edison
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1356 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...