• 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 item from list
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Removing item from list


  • Subject: Re: Removing item from list
  • From: Paul Berkowitz <email@hidden>
  • Date: Sat, 15 Sep 2001 10:28:35 -0700

On 9/15/01 9:45 AM, "Irwin Poche" <email@hidden> wrote:

> Is there a native way to remove items from a list ?
>
> This doesn't...
>
> set x to {"a","b","c","d"}
> set x to x - {"c"}

Not like that. The minus sign is an arithmetic operator for numbers (and is
also used to indicate "starting from the end" in lists). You have to do it
in a repeat loop, unfortunately. Honestly, it's where osaxen like Akua
Sweets' 'the list made' really come into their own.

Now that I'm in OS X a lot of the time, I've had to come up with tedious
little routines such as osaxen-haters have been using all along. Here's a
boring little loop that works for either one item, as yours above, or for a
whole sublist of items to remove:

to RemoveListItems(theList, exclItems) -- both lists

local tempList, theItem

set tempList to {}
repeat with i from 1 to (count theList)
set theItem to item i of theList
if {theItem} is not in exclItems then
set end of tempList to theItem
end if
end repeat

return tempList

end RemoveListItems

set x to {"a", "b", "c", "d"}

RemoveListItems(x, {"c"})

--> {"a", "b", "d"}



[You could cut it down to act just on a single item instead of a sublist,
but it's handier as above. Cut down version:

to RemoveSingleListItem(theList, exclItem)

local tempList, theItem

set tempList to {}
repeat with i from 1 to (count theList)
set theItem to item i of theList
if theItem /= exclItem then
set end of tempList to theItem
end if
end repeat

return tempList

end RemoveSingleListItem

set x to {"a", "b", "c", "d"}

RemoveSingleListItem(x, "c")
--> {"a", "b", "d"}

]

--
Paul Berkowitz


References: 
 >Removing item from list (From: Irwin Poche <email@hidden>)

  • Prev by Date: Re: Removing item from list
  • Next by Date: Re: Removing item from list
  • Previous by thread: Re: Removing item from list
  • Next by thread: Re: Scriptable Text Editor
  • Index(es):
    • Date
    • Thread