How to expand this in a script?

In a script, ss there a way to expand this:
set a = [tr][xyz]
to
tx ty tz rx ry tz

expandpattern()
thx