filter?

Michael Kann mikekann at yahoo.com
Wed Jun 22 22:19:34 EDT 2011


If you want to use a SORT you can try something like the following:

on mouseUp
put "1,2,3,4" into v
put "1,2,3,4,5" & cr before v
replace comma with cr in v
sort v
repeat for each line x in v
  if x & cr & x is not in v then
    put x & cr after h
  end if
end repeat
put h into fld 3 -- "5"
end mouseUp

--- On Wed, 6/22/11, Pete <pete at mollysrevenge.com> wrote:

From: Pete <pete at mollysrevenge.com>
Subject: Re: filter?
To: "How to use LiveCode" <use-livecode at lists.runrev.com>
Date: Wednesday, June 22, 2011, 8:30 PM

I have a feeling this is probably going to get a lot of responses related to
the most efficient way to do this!  I have no idea how efficient this would
be but I'll start the ball rolling with this code.

repeat with x=1 to the number of lines in tlist1
  if line x of tlist1 is not among the lines of tlist 2 then
    < you found a unique tlist1 value >
  end if
end repeat
repeat with x=1 to the number of lines in tlist2
  if line x of tlist2 is not among the lines of tlist1 then
    < you found a unique tlist2 value >
  end if
end repeat

Another thought I had involves using an array as follows:

repeat with x=1 to the number of lines in tlist1
  add 1 to array[line x of tlist1]
end repeat
repeat with x=1 to the number of lines in tlist2
  add 1 to array[line x of tlist2]
end repeat
repeat for each key myKey in array
  if array[myKey]=1 then
    < you found a unique value >
  end if
end repeat

Depending on how many entries you expect in each list and how long each
entry is, the array solution could chew up a huge amount of memory.

These are both pretty simplistic solutions which probably means they
wouldn't be the fastest.  I have no idea how fast either of them might be
and I know there are definitely some efficiencies to be had by using either
repeat with vs repeat for but I can't remember which is the faster.


Pete
Molly's Revenge <http://www.mollysrevenge.com>




On Wed, Jun 22, 2011 at 5:38 PM, Nicolas Cueto <niconiko at gmail.com> wrote:

> Hi again.
>
> Given 2 lists of cr-delimited values (tList1, tList2), what's the fastest
> way of getting the unique value(s)?
>
> Ex, "1,2,3,4" & "1,2,3,4,5" = "5"
> (but cr instead of comma)
>
> Thanks.
>
> --
> Nicolas Cueto (iPhone)
> _______________________________________________




More information about the Use-livecode mailing list