Re: Removing items from a list
Re: Removing items from a list
- Subject: Re: Removing items from a list
- From: Steve Meyer <email@hidden>
- Date: Sat, 6 Mar 2004 15:35:02 -0700
Using recursion and the remarkable "rest of" command, and directly
plagiarizing Matt Neuburg and AS:The Definitive Guide (page 153):
set x to {"fu", "foo", "bar", "fu", "foobar", "fubar"}
set z to {"fu", "foobar"}
on deleteItems(theSet, DeleteThese)
if theSet = {} then return theSet
if item 1 of theSet is in DeleteThese then
return deleteItems((rest of theSet), DeleteThese)
else
return {item 1 of theSet} & deleteItems((rest of theSet), DeleteThese)
end if
end deleteItems
set y to deleteItems(x, z)
y
--> {"foo", "bar", "fubar"}
Steve
On Mar 6, 2004, at 2:09 PM, Michelle Steiner wrote:
This came up on the Applescript newsgroup. Someone wanted to be able
to remove all instances of certain items from a list. Here was my
solution; I'm sure I'm not the first person to have come up with it.
set x to {"fu", "foo", "bar", "fu", "foobar", "fubar"}
-- remove items matching "fu" and "fubar" from x
set z to {"fu", "foobar"}
set xx to {}
repeat with a in x
if a is not in z then
copy contents of a to end of xx
end if
end repeat
xx
--> {"foo", "bar", "fubar"}
Too bad "whose" and the like don't work on lists...
-- Michelle
_______________________________________________
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.