Re: Removing (or picking) items from list 1 via list 2?
Re: Removing (or picking) items from list 1 via list 2?
- Subject: Re: Removing (or picking) items from list 1 via list 2?
- From: Arthur J Knapp <email@hidden>
- Date: Tue, 23 Apr 2002 19:21:05 -0400
>
Date: Tue, 23 Apr 2002 18:06:38 +0100
>
From: Charles Arthur <email@hidden>
>
Subject: Removing (or picking) items from list 1 via list 2?
>
Here's the problem, speed freaks.
;-)
>
I have a list - list1 - which could get quite large - say, 400-500 items,
>
all OS aliases.
>
Meanwhile I also have list2 which will also have lots of aliases. Might
>
easily be bigger than list1.
>
I want to pick things randomly from list1 that aren't in list2, to create
>
mywanteditem.
-- Method 1
--
set someItem to some item of list1
repeat until someItem is not in list2
set someItem to some item of list1
end repeat
someItem --> random item of list1 not found in list2
(*
* Problem : Infinite loop if every item of list1 is in list2
*)
-- Method 2, (highly optimized)
--
script o
property a1 : {}
property a2 : {}
property a3 : {}
end script
set o's a1 to list1
set o's a2 to list2
repeat with i from 1 to o's a1's length
tell (o's a1's item i) to ,
if (it is not in o's a2) then ,
set o's a3's end to it
end repeat
if (o's a3's length is not 0) then
set someItem to some item of o's a3
else
-- Every item of list1 is in list2
end if
>
... vanilla because I want to include it in some code I'll be
>
distributing.
Naturally. :)
{ Arthur J. Knapp, of <
http://www.STELLARViSIONs.com>
<
mailto:email@hidden>
try
<
http://www.appleklub.cz/~koudelka/home.shtml>
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.