How to get the difference between two lists?

Richard Gaskin ambassador at fourthworld.com
Sun Apr 3 23:49:04 EDT 2005


Ken Ray wrote:
> I've got two lists - one with is the "comprehensive" list that is
> return-delimited, like:
> 
> 3
> 5
> 6
> 7
> 11
> 14
> 18
> 21
> 
> And another list which is the list I would like to *remove* from the
> comprehensive list:
> 
> 5
> 6
> 11
> 18
> 
> Which should give me:
> 
> 3
> 7
> 14
> 21
> 
> I can of course do a repeat loop through the small list and remove those
> items from the comprehensive list, but I'm wondering if there's a faster way
> to do this. The numbers will always be sorted in ascending numeric order,
> but there may be thousands of them, so I'm not looking forward to a repeat
> loop. 

With 10,000 lines in my main list and 5,000 lines in my exclude list, it
takes only 25 milliseconds to use this on my single-processor PBG4 1MHz:


function ShortList pList, pExcludelist
   repeat for each line tLine in pList
     if tLine is not among the lines of pExcludeList then
       put tLine & cr after tNulist
     end if
   end repeat
   delete last char of tNuList
   return tNuList
end ShortList


--
  Richard Gaskin
  Fourth World Media Corporation
  __________________________________________________
  Rev tools and more: http://www.fourthworld.com/rev


More information about the use-livecode mailing list