Removing (or picking) items from list 1 via list 2?
Removing (or picking) items from list 1 via list 2?
- Subject: Removing (or picking) items from list 1 via list 2?
- From: Charles Arthur <email@hidden>
- Date: Tue, 23 Apr 2002 18:06:38 +0100
Hi.
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.
I had thought of
--
set found to false
repeat until found is true
set randomnum to (random number from 1 to count items in list1)
if item randomnum of list1 is not in list2 then
set mywanteditem to item randomnum of list1
set found to true
end repeat
mywanteditem
--
But I wonder if the fastest way eventually might be
Is the best way to create list3, by eg
--
set list3 to {}
set list3ref to a reference to list3
repeat with anitem in list1
if anitem is not in list2 then set end of list3ref to anitem
end repeat
set randomnum to randomnumber from 1 to count items in list3
set mywanteditem to item randomnum of list3
--
?
Which is the more efficient way? Or is there an even more efficient method?
This is all in the context of a big repeat loop where the contents of list1
will keep changing (it'll be created afresh, but get smaller, with each
loop).
Also: using OSX, vanilla because I want to include it in some code I'll be
distributing.
Charles
----------------------------
http://www.ukclimbing.com : 1100+ British crags, 350+ British climbing
walls - searchable by distance and anything else you care to think of -
with weather forecasts for every one, plus maps, articles, news and
features. And there's even a cool shop attached.
________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs SkyScan
service. For more information on a proactive anti-virus service working
around the clock, around the globe, visit
http://www.messagelabs.com
________________________________________________________________________
_______________________________________________
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.