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.


|