Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Applescript > Re: applescript...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 5 Topic 1606 of 1658
Post > Topic >>

Re: applescript remove duplicate list items

by Phantom <phantom@[EMAIL PROTECTED] > May 1, 2008 at 03:43 AM

On 2008-04-28 16:56:07 -0700, simon@[EMAIL PROTECTED]
 (Simon 
Wolf) said:

> Dave Balderstone <dave@[EMAIL PROTECTED]
> wrote:
> 
>> In article <2008042815593316807-phantom@[EMAIL PROTECTED]
>, Phantom
>> <phantom@[EMAIL PROTECTED]
> wrote:
>> 
>>> I'm wondering if anyone here knows of an elegant way to eliminate 
>>> duplicate values from an applescript list.
>>> 
>>> e.g. taking this list:
>>> {"apple", "orange", "apple", "watermelon", "orange"}
>>> 
>>> and returning
>>> {"apple", "orange", "watermelon"}
>>> 
>>> 
>>> not a big priority, but it would help with one of my scripts. could't
>>> find a answer with google, unfortunately, sorry to bother if this
comes
>>> up a lot.
>>> 
>>> thanks guys.
>> 
>> Try this:
>> 
>> set list1 to {"apple", "orange", "apple", "watermelon", "orange"}
>> set list2 to {"apple", "orange", "watermelon"}
>> set list3 to {}
>> 
>> repeat with x from 1 to count of items of list1
>> set n to item x of list1
>> if n is in list2 and n is not in list3 then set end of list3 to n
>> end repeat
>> 
>> return list3
> 
> Sorry Dave but I've modified your code because I think that the original
> post relates to a situation where there is only one list. If this is the
> case then you need:
> 
> on run
>     set list1 to {"apple", "orange", "apple", "watermelon", "orange"}
>     set list2 to {}
> 
>     repeat with x from 1 to count of items of list1
>         set n to item x of list1
>         if n is not in list2 then set end of list2 to n
>     end repeat
> 
>     return list2
> end run

you're right on the mark... just one list. I figured there might have 
been some list math possible, but this works great, too. thanks!
P.
 




 5 Posts in Topic:
applescript remove duplicate list items
Phantom <phantom@[EMAI  2008-04-28 22:59:33 
Re: applescript remove duplicate list items
Dave Balderstone <dave  2008-04-28 17:25:43 
Re: applescript remove duplicate list items
simon@[EMAIL PROTECTED]   2008-04-29 00:56:07 
Re: applescript remove duplicate list items
Dave Balderstone <dave  2008-04-28 18:08:33 
Re: applescript remove duplicate list items
Phantom <phantom@[EMAI  2008-05-01 03:43:53 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Sep 6 22:53:55 CDT 2008.