Jump to content
Sign in to follow this  
Gistya Eusebio

A couple of one-liner list functions.

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

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

Recommended Posts

(1)

// To remove all instances of [test] from list:

while (~q = llListFindList(listy,[test])) listy = llDeleteSubList(listy,q,q);

// Proof of concpet:

integer test = 5;
list listy = [3,3,4,5,2,1,6,5,3,5,5,2,3,2,1,5,5,3,2,2,5,5,5,5,2,1,1,3,3,5];
integer q;
while (~q = llListFindList(listy,[test])) listy = llDeleteSubList(listy,q,q);
llSay(0, llList2CSV(listy));

// returns:  3, 3, 4, 2, 1, 6, 3, 2, 3, 2, 1, 3, 2, 2, 2, 1, 1, 3, 3

(2) corollary

// To replace all instances of [test] from list with [replacement]: 

while (~q = llListFindList(listy,[test])) listy = llListReplaceList(listy,replacement,q,q+llGetListLength(test)-1);

// Proof of concept: (using variable declarations still from example above)

listy = [3,3,4,5,2,1,6,5,3,5,5,2,3,2,1,5,5,3,2,2,5,5,5,5,2,1,1,3,3,5];
list replacement = ["The creatures became incredibly obsessed with cat food."];
while (~q = llListFindList(listy,[test])) listy = llListReplaceList(listy,replacement,q,q+llGetListLength(test)-1);
llSay(0, llList2CSV(listy));

// returns:  3, 3, 4, The creatures became incredibly obsessed with cat food., 2, 1, 6, The creatures became incredibly obsessed with cat food., 3, The creatures became incredibly obsessed with cat food., The creatures became incredibly obsessed with cat food., 2, 3, 2, 1, The creatures became incredibly obsessed with cat food., The creatures became incredibly obsessed with cat food., 3, 2, 2, The creatures became incredibly obsessed with cat food., The creatures became incredibly obsessed with cat food., The creatures became incredibly obsessed with cat food., The creatures became incredibly obsessed with cat food., 2, 1, 1, 3, 3, The creatures became incredibly obsessed with cat food.

=G=

  • Like 1

Share this post


Link to post
Share on other sites

tried the corallary but had to change it a bit?

        integer test = 5;
        integer q;
        list listy = [3,3,4,5,2,1,6,5,3,5,5,2,3,2,1,5,5,3,2,2,5,5,5,5,2,1,1,3,3,5];
        list replacement = ["five gone."];
        while (~q = llListFindList(listy,[test]))  listy = llListReplaceList(listy,replacement,q,q) ;
        llSay(0, llList2CSV(listy));

 

 btw: ty for these...great work :)

Share this post


Link to post
Share on other sites
You are about to reply to a thread that has been inactive for 2547 days.

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...