Converting a List of Lists to a Dictionary

I was just working on my ASObjC notebook, and the goal was to convert a list of lists to a dictionary. I had hoped to avoid the use of a repeat loop but without success. In testing with Script Geek, the first script took 6 milliseconds and only 2 milliseconds if a script object was employed. The second script took 16 milliseconds, and the use of a script object actually increased the execution time.

The list of lists used in the tests was:

set theList to {{"a", "aaa"}, {"b", "bbb"}, {"c", "ccc"}, {"d", "ddd"}, {"e", "eee"}, {"f", "fff"}, {"g", "ggg"}, {"h", "hhh"}, {"i", "iii"}, {"j", "jjj"}, {"k", "kkk"}, {"l", "lll"}, {"m", "mmm"}, {"n", "nnn"}, {"o", "ooo"}, {"p", "ppp"}, {"q", "qqq"}, {"r", "rrr"}, {"s", "sss"}, {"t", "ttt"}, {"u", "uuu"}, {"v", "vvv"}, {"w", "www"}, {"x", "xxx"}, {"y", "yyy"}, {"z", "zzz"}}

Tested script one was:

use framework "Foundation"
-- insert theList here
set {theKeys, theValues} to {{}, {}}
repeat with aList in theList -- timing result is 6 milliseconds
	-- repeat with aList in my theList -- reduces timing result to 2 milliseconds
	set {end of theKeys, end of theValues} to {item 1 of aList, item 2 of aList}
end repeat
set theDictionary to current application's NSDictionary's dictionaryWithObjects:theValues forKeys:theKeys

Tested script two was:

use framework "Foundation"
-- insert theList here
set theDictionary to (current application's NSMutableDictionary's new())
repeat with aList in theList
	(theDictionary's setObject:(item 2 of aList) forKey:(item 1 of aList))
end repeat -- 16 milliseconds

A slight variant of script two was to bridge theList to an array and then to loop through the array but the timing result was about the same.

Anyone having a need to convert a list of lists to a dictionary would probably want to do that in a handler, perhaps as shown below. The timing result was 2 milliseconds.

use framework "Foundation"

set theList to {{"a", "aaa"}, {"b", "bbb"}, {"c", "ccc"}, {"d", "ddd"}, {"e", "eee"}, {"f", "fff"}, {"g", "ggg"}, {"h", "hhh"}, {"i", "iii"}, {"j", "jjj"}, {"k", "kkk"}, {"l", "lll"}, {"m", "mmm"}, {"n", "nnn"}, {"o", "ooo"}, {"p", "ppp"}, {"q", "qqq"}, {"r", "rrr"}, {"s", "sss"}, {"t", "ttt"}, {"u", "uuu"}, {"v", "vvv"}, {"w", "www"}, {"x", "xxx"}, {"y", "yyy"}, {"z", "zzz"}}

set theDictionary to listToDictionary(a reference to theList)

on listToDictionary(theList)
	set {theKeys, theValues} to {{}, {}}
	repeat with aList in theList
		set {end of theKeys, end of theValues} to {item 1 of aList, item 2 of aList}
	end repeat
	return (current application's NSDictionary's dictionaryWithObjects:theValues forKeys:theKeys)
end listToDictionary -- 2 milliseconds