Difference between revisions of "ListXxorY"
Jump to navigation
Jump to search
Void Singer (talk | contribs) m (examples should at least compile) |
m (<lsl> tag to <source>) |
||
Line 11: | Line 11: | ||
< | <source lang="lsl2"> | ||
list ListXxorY(list lx, list ly) { // return elements that are in X or Y but not both | list ListXxorY(list lx, list ly) { // return elements that are in X or Y but not both | ||
return ListXnotY( lx, ly) + ListXnotY( ly, lx); | return ListXnotY( lx, ly) + ListXnotY( ly, lx); | ||
} | } | ||
</ | </source> | ||
Example:<br /> | Example:<br /> | ||
< | <source lang="lsl2"> | ||
list l1 = ["a","b","c","d"]; | list l1 = ["a","b","c","d"]; | ||
list l2 = ["a","1","b","2","c","3"]; | list l2 = ["a","1","b","2","c","3"]; | ||
Line 44: | Line 44: | ||
} | } | ||
} | } | ||
</ | </source> | ||
</div> | </div> |
Revision as of 14:26, 22 January 2015
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Function: list ListXnotY(list lx, list ly);
Returns a new list, composed of elements that were in either original script, but not both.
Note: This is not the same as getting rid duplicates by preserving just one of each duplicated item. It goes further, and removes both items.
See also: Lists
list ListXxorY(list lx, list ly) { // return elements that are in X or Y but not both
return ListXnotY( lx, ly) + ListXnotY( ly, lx);
}
Example:
list l1 = ["a","b","c","d"];
list l2 = ["a","1","b","2","c","3"];
list ListXxorY(list lx, list ly) { // return elements that are in X or Y but not both
return ListXnotY( lx, ly) + ListXnotY( ly, lx);
}
list ListXnotY(list lx, list ly) {// return elements in X list that are not in Y list
list lz = [];
integer i = 0;
integer n = llGetListLength(lx);
for (; i < n; i++)
if (llListFindList(ly,llList2List(lx,i,i)) == -1)
lz += llList2List(lx,i,i);
return lz;
}
default{
state_entry() {
llSay(0, "Elements that are in x list or y list but not both: " + llList2CSV(ListXxorY(l1,l2)));
//will say: d, 1, 2, 3
}
}
Posted with the kind permission of Very Keynes, who originated this script June 2007 in the SL scripters forum http://forums-archive.secondlife.com/54/e4/194138/1.html