Re: Flattening Nested Lists
Re: Flattening Nested Lists
- Subject: Re: Flattening Nested Lists
- From: Philip Aker <email@hidden>
- Date: Tue, 27 Jan 2009 08:30:51 -0800
On 2009-01-26, at 16:46:45, Nigel Garvey wrote:
Another alternative, which performs surprisingly well (with short
lists at least), uses nested repeats and concatenation instead of
recursion:
on flattenList(theList)
repeat until (count theList's lists) is 0
set flatterList to {}
repeat with i from 1 to (count theList)
set x to item i of theList
if (x's class is list) then
set flatterList to flatterList & x
else
set flatterList to flatterList & {x}
end if
end repeat
set theList to flatterList
end repeat
return theList
end flattenList
set deep to {{"item 1", 0, {"item 3", "item 4", "item 5"}},
{{name:"Michael"}, "item 7", "item 8"}, 999}
flattenList(deep)
Thanks Nigel,
I've added it to my NGLightning folder.
Philip Aker
echo email@hidden@nl | tr a-z@. p-za-o.@
Democracy: Two wolves and a sheep voting on lunch.
_______________________________________________
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