Re: Flattening Nested Lists
Re: Flattening Nested Lists
- Subject: Re: Flattening Nested Lists
- From: Rick Gordon <email@hidden>
- Date: Mon, 26 Jan 2009 02:15:16 -0800
Thanks, Barry.
------------------
On 1/26/09 at 9:52 AM +0000, Barry Wainwright wrote in a message entitled
"Re: Flattening Nested Lists":
>On 26 Jan 2009, at 09:30, Rick Gordon wrote:
>
>>I'm spending too much time trying to do something that I think should be easy enough: flattening a list of lists (of lists (of lists)), so that the the result is a list containing no list elements. Can someone point me to some code or instruction on handling this? I'm figuring that it probably takes a recursive handler, but I'm getting recursed in my own mind, at this point.
>
>
>set aList to {{"item 1", "item 2", {"item 1", "item 2", "item 3"}}, {"item 1", "item 2", "item 3"}, "item 3"}
>set newList to {}
>my flattenList(aList)
>newList
>
>on flattenList(theList)
> global newList
> repeat with anItem in theList
> if class of anItem is list then
> my flattenList(anItem)
> else
> copy anItem to end of newList
> end if
> end repeat
>end flattenList
--
___________________________________________________
RICK GORDON
EMERALD VALLEY GRAPHICS AND CONSULTING
___________________________________________________
WWW: http://www.shelterpub.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden