• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Trimming down a list
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trimming down a list


  • Subject: Re: Trimming down a list
  • From: Arthur J Knapp <email@hidden>
  • Date: Wed, 10 Apr 2002 16:41:26 -0400

> Date: Wed, 10 Apr 2002 14:34:32 +0100
> Subject: Trimming down a list
> From: Steve Thompson <email@hidden>

> I have this script
>
> set mrt to {long list of 10,000+ items created from a text file)
> set k to {}
> repeat with i from 1 to (the number of items in mrt)
> if item i of mrt is not in k then set k to k & (item i of mrt)

> ...the idea being that k contains a list of unique items based on whats in
> mrt
>
> Is there a quicker way to do this or an OSAX that will do it for me?

Simple change the concatenation process to an appending proccess:

> if item i of mrt is not in k then set k to k & (item i of mrt)
if item i of mrt is not in k then set (end of k) to item i of mrt

This will greatly speed things up. From that point, you may want to
consider working with references:

set mrt to {long list of 10,000+ items created from a text file)
set k to {}

set refMrt to a reference to mrt
set refK to a reference to k

repeat with i from 1 to refMrt's length
if ( refMrt's item i is not in refK ) then
set refK's end to refMrt's item i
end
end


Within a handler, you can use the "Serge" technique:

on RemoveDuplicates(a)

script o
property a : {} --> array of items
property u : {} --> collect unique items
end script
set o's a to a

repeat with i from 1 to o's a's length
if ((o's a's item i) is not in (o's u)) then
set (o's u's end) to o's a's item i
end if
end repeat

return o's u

end RemoveDuplicates

set k to RemoveDuplicates( mrt )


{ Arthur J. Knapp, of <http://www.STELLARViSIONs.com>
<mailto:email@hidden>
try
<http://www.AppleScriptSourcebook.com/>
on error number -128
end try
}
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: InDesign scripting (a bug?)
  • Next by Date: Re: Trimming down a list
  • Previous by thread: Re: Trimming down a list
  • Next by thread: Re: Trimming down a list
  • Index(es):
    • Date
    • Thread