Re: Removing item from list
Re: Removing item from list
- Subject: Re: Removing item from list
- From: Deivy Petrescu <email@hidden>
- Date: Sat, 15 Sep 2001 13:38:56 -0400
At 1:18 PM -0400 9/15/01, Bryan wrote:
set x to {"a", "b", "c", "d"}
set z to {}
repeat with y in x
if y is not "c" then set z to z & y
end repeat
set x to z
I use Satimage OSAX Suppress Item:
set x to {"a", "b", "c", "d"}
suppress item "c" from x
I don't know if its any faster.
Saving characters in long scripts is important if you want to be able to
run an
event log debugger (if you don't have Script Debugger (which I don't))
due to
the 32k limit.
Bryan Kaufman
It is very fast.
Instead of Satimage osax one can use the "Satimage sort".
That is an adaptation of the sort routine by E. Levy from Satimage.
There is one major difference besides time, this one eliminates all
occurrences of "c".
See the example below
____
set lista to {}
repeat with l from 1 to 20
repeat with z from 1 to 20
set end of lista to z
end repeat
end repeat
--suppress item 15 from lista
--set newlista to removeitem(lista, 15)
--newlista
on removeitem(lista, ditem)
set removedlista to {}
repeat with l in lista
if contents of l ditem then set removedlista to
removedlista & l
end repeat
return removedlista
end removeitem
____
One can make minor changes to eliminate only one instance of the item.
Regards
Deivy Petrescu
http://www.dicas.com