Re-arrange a list of lists in AppleScript

Posted by: waggy-d

Re-arrange a list of lists in AppleScript - 04/12/12 12:43 PM

Ok, so I've got a task that I can't seem to figure out. Here is an example of the problem; please note that I don't need a solution to this specific data, but a solution to the type of data as the list may grow and change over time.

I have a list of lists:
{{"Company 1", "Email 1", "First 1", "Last 1", "Title 1", "Artist 1"}, {"Company 1", "Email 1", "First 1", "Last 1", "Title 2", "Artist 2"}, {"Company 2", "Email 2", "First 2", "Last 2", "Title 3", "Artist 3"}, {"Company 3", "Email 3", "First 3", "Last 3", "Title 4", "Artist 4"}, {"Company 4", "Email 4", "First 4", "Last 4", "Title 5", "Artist 5"}, {"Company 4", "Email 4", "First 4", "Last 4", "Title 6", "Artist 6"}, {"Company 4", "Email 4", "First 4", "Last 4", "Title 7", "Artist 7"}}


Here is the same list in grid format as it may make it easier to read: Each row represents a list within the list.

Company 1 Email 1 First 1 Last 1 Title 1 Artist 1
Company 1 Email 1 First 1 Last 1 Title 2 Artist 2
Company 2 Email 2 First 2 Last 2 Title 3 Artist 3
Company 3 Email 3 First 3 Last 3 Title 4 Artist 4
Company 4 Email 4 First 4 Last 4 Title 5 Artist 5
Company 4 Email 4 First 4 Last 4 Title 6 Artist 6
Company 4 Email 4 First 4 Last 4 Title 7 Artist 7


What I need is for it to be re-worked into a list of lists as such:
{{{"Company 1", "Email 1", "First 1", "Last 1"}, {{"Title 1", "Artist 1"}, {"Title 2", "Artist 2"}}}, {{"Company 2", "Email 2", "First 2", "Last 2"}, {{"Title 3", "Artist 3"}}}, {{"Company 3", 'Email 3", "First 3", "Last 3"}, {{"Title 4", "Artist 4"}}}, {{"Company 4", "Email 4", "First 4", "Last 4"}, {{"Title 5", "Artist 5"}, {"Title 6", "Artist 6"}, {"Title 7", "Artist 6"}}}

So each unique "Company" along with it's contact info would only be once and then along with it's associated song titles/artists.

Any help would really be appreciated as I just haven't been able to nail it down.

Thanks