• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Removing items from a list
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


  • Follow-Ups:
    • Re: Removing items from a list
      • From: "John C. Welch" <email@hidden>
    • Re: Removing items from a list
      • From: Michael Terry <email@hidden>
References: 
 >Removing items from a list (From: Michelle Steiner <email@hidden>)

  • Prev by Date: Re: Text into Mail message content
  • Next by Date: Re: Removing items from a list
  • Previous by thread: Removing items from a list
  • Next by thread: Re: Removing items from a list
  • Index(es):
    • Date
    • Thread