Convert List to records

I have a list, like so:

{17.0, 2, 19.0, 2, 20.0, 3, 22.0, 5, 27.0, 3}

I want to turn it into a list of records as so:

a:17.0, b:2
a:19.0 b:2
a: 20. 0 b:3
a: 22.0 b:5
a:27.0 b:3

If possible, I want to do this in “vanilla AppleScript” – no extensions, no ducking out to another language.

Model: 13-inch Mac Air running Mojave
AppleScript: 2.7
Browser: Safari 605.1.15
Operating System: macOS 10.14

This should do it:

set myString to {17.0, 2, 19.0, 2, 20.0, 3, 22.0, 5, 27.0, 3}
set myString2 to {}
set i to 1
repeat ((count of myString) / 2) times 
	set end of myString2 to {a:myString's item i, b:myString's item (i + 1)}
	set i to (i + 2)
end repeat

A slightly more condensed and efficient version:

set L to {17.0, 2, 19.0, 2, 20.0, 3, 22.0, 5, 27.0, 3}
set R to {}

repeat with i from 1 to length of L by 2
		set end of R to {a:item i, b:item (i + 1)} of L
end repeat

return R

Neat !!!

It’s interesting that {a:item i, b:item (i + 1)} of L actually works. Presumably the compiler sees the line as something like:

tell L to set end of R to {a:item i, b:item (i + 1)}

Thanks to all. I didn’t just get an answer, I learned something. This is my first AppleScript project and I’ve been struggling with some of the commands in JavaScript/Python (or even Unix Shell Script).

It’s one reason I’m fond of AppleScript, because oddities that crop up in a pleasing way are never something I would have naturally predicted.