Sorting a paired list

I found another thread that used shell scripting to sort a list. It was pretty cool but I have a need to show a list of colors and a matching substitute color. I was thinking this would be in a list of two-item lists to keep the pairs matched. I would like to display the list in alphabetical order based on the original color. Does anyone have any ideas how this could be done in a minimal amount of code?

This works, and is nice and short, for a list of single color names:

set theList to {"Pantone 300", "White Variable", "Black", "Other Color"}
set text item delimiters of AppleScript to ASCII character 10
set theList to "" & theList
set text item delimiters of AppleScript to ""
do shell script "echo " & quoted form of theList & " | /usr/bin/sort"
set theList to paragraphs of result

But I want to sort this list and end up with a new list that still has the paired up colors:

set theList to {{"Pantone 300 Variable", "Pantone 300"}, {"White Variable", "Paper"}, {"FPO Variable Color", "Black"}, {"Legally Approved", "Black"}}

I want the result to be:
{{“FPO Variable Color”, “Black”}, {“Legally Approved”, “Black”}, {“Pantone 300 Variable”, “Pantone 300”}, {“White Variable”, “Paper”}}

Model: PowerPC G5 Tower OS 10.4.8
AppleScript: XCode 2.5
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

Matt:

For multiple item lists, I have always used a bubblesort routine. It is pretty fast, even up to a couple hundred items:

set theList to {{"Pantone 300 Variable", "Pantone 300"}, {"White Variable", "Paper"}, {"FPO Variable Color", "Black"}, {"Legally Approved", "Black"}}
set sorted_List to (my bubblesort(theList))
sorted_List
-->{{"FPO Variable Color", "Black"}, {"Legally Approved", "Black"}, {"Pantone 300 Variable", "Pantone 300"}, {"White Variable", "Paper"}}

on bubblesort(array)
	repeat with i from length of array to 2 by -1 --> go backwards
		repeat with j from 1 to i - 1 --> go forwards
			tell array
				if ((item j)'s item 1) > ((item (j + 1))'s item 1) then
					set {item j, item (j + 1)} to {item (j + 1), item j} -- swap
				end if
			end tell
		end repeat
	end repeat
	return array
end bubblesort

Hope this helps,

Awesome! That’s perfect. Thanks.