Re: consolidate lists
Re: consolidate lists
- Subject: Re: consolidate lists
- From: Ed Stockly <email@hidden>
- Date: Mon, 19 May 2008 07:05:10 -0700
On May 18, 2008, at 7:17 PM, Hudson Barton wrote:
I'm looking for the best way, in applescript, to consolidate lists
into a record like this:
set List1 to {{person1,cat1},{person2,cat1}}
set List2 to {{person1,cat2},{person2,chat2},{person3,cat2}}
<script>
Result = {{Name:person1, Cats:cat1,cat2}{Name:person2,
Cats:cat1,cat2}{Name:person3,Cats:cat3}}
Something like this should get you started...
------------
property processedLists : {}
set List1 to {{"person1", "cat1"}, {"person2", "cat1"}}
set List2 to {{"person1", "cat2"}, {"person2", "chat2"}, {"person3",
"cat2"}}
set processedLists to {}
set the end of processedLists to my ProcessList(List1)
set the end of processedLists to my ProcessList(List2)
log processedLists
(*
name:person1, cats:cat1, cat2, name:person2, cats:cat1, chat2,
name:person2, cats:cat1, name:person3, cats:cat2, name:person3,
cats:cat2
*)
on ProcessList(sourceList)
repeat with thisList in sourceList
set {thisName, thisCat} to thisList
set foundName to false
repeat with x from 1 to the count of processedLists
set thisRec to item x of processedLists
if name of thisRec = thisName then
set the end of cats of item x of processedLists to thisCat
set foundName to true
exit repeat
end if
end repeat
if not foundName then set the end of processedLists to
{name:thisName, cats:{thisCat}}
end repeat
end ProcessList
_______________________________________________
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