This handler, is so sweet, when you have “indexes” with unique items.
I don’t know how fast it is as it stands below, but it saves me the trouble of having to maintain the inverted table.
So it saves time, and room for errors! It is the handler in post #20, reworked from post #12 slightly reworked.
(* -- http://macscripter.net/viewtopic.php?pid=155040#p155040
set the_list to {{"Me", "Red"}, {"You", "Blue"}, {"They", "Green"}}
set rests to getSingelton(the_list, "They") --> "Green"
set rests to getSingelton(the_list, "Blue") --> "You"
set rests to getSingelton(the_list, "NO") --> null
set rests to getSingelton(the_list, "Red") --> "Me"
set rests to getSingelton(the_list, "you") --> "Blue"
*)
to getSingelton(the_list, item_a)
local p, q, tids
” Foundation by Nigel Garvey
set {tids, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}
set the_list_as_string to the_list as text
set AppleScript's text item delimiters to item_a
try
if text item 1 of the_list_as_string = "" then
set q to paragraph 2 of text item 2 of the_list_as_string
else
set p to (count paragraphs of text item 1 of the_list_as_string) mod 2
set q to paragraph (p * 4 - 2) of text item (p + 1) of the_list_as_string
end if
set AppleScript's text item delimiters to tids
on error
set AppleScript's text item delimiters to tids
return null
end try
if q is item 1 of last item of the_list then
if item_a is item 2 of last item of the_list then
return q
else
return null
end if
else
return q
end if
end getSingelton