Re: Flattening Nested Lists
Re: Flattening Nested Lists
- Subject: Re: Flattening Nested Lists
- From: "Mark J. Reed" <email@hidden>
- Date: Mon, 26 Jan 2009 08:56:57 -0500
On Mon, Jan 26, 2009 at 7:53 AM, Philip Aker <email@hidden> wrote:
> You're correct. A better plan is to use a parameter for output.
Why do you need either one? Why not just have the handler return the
flattened list? This seems to work fine:
on flatten(aList)
if class of aList is not list then
return { aList }
else if length of aList is 0 then
return aList
else
return flatten(first item of aList) & flatten(rest of aList)
end
end flatten
flatten({{1,2},3,{4,{5,{6,7},8}}})
> In many cases though I believe there will be performance improvements using
> Serge/Garvey techniques or making it a script.
> on FlattenList(theList, outResult)
> repeat with i in theList
> if (class of i is list) then
> my FlattenList(i, outResult)
> else
> set end of outResult to contents of i
> end if
> end repeat
> end FlattenList
> set deep to {{"item 1", 0, {"item 3", "item 4", "item 5"}},
> {{name:"Michael"}, "item 7", "item 8"}, 999}
> set outResult to {}
> my FlattenList(deep, outResult)
> outResult
>
> Philip Aker
> echo email@hidden@nl | tr a-z@. p-za-o.@
> Democracy: Two wolves and a sheep voting on lunch.
>
--
Mark J. Reed <email@hidden>
_______________________________________________
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