From: tomk on
On Jul 29, 8:52 am, tomk <krehbiel....(a)gmail.com> wrote:
> On Jul 28, 10:52 pm, ashneerson <ashneer...(a)gmail.com> wrote:
>
> > hi, have a puzzle with rotating a list like below
>
> > {{ht a3 pr2} {ht a2 pr1} {lt a1 pr2} {lt a3 pr4} {ht a2 pr2}}
>
> > into a list like this one:
>
> > {{ht ht ht lt lt}  {a2 a2 a1 a3}  {pr1 pr2 pr2 pr2 pr4}}
>
> > so that to rotate the columns to rows and retain original
> > correspondence between the list elements.
>
> > can someone please help me figure out the trick?
> > -a.
>
> For the case given you could do the following (assuming the first list
> is in a variable named alist).
>
> foreach a b c d e {*}${alist} {
> lappend result [list $a $b $c $d $e]
>
> }
>
> The result isn't exactly the same result suggested because it appears
> the elements is the suggested result appear to have been sorted while
> my example is a rotation.
>
> tomk

OOPS,
The above code doesn't work. This is what it should have been.

set alist [list {ht a3 pr2} {ht a2 pr1} {lt a1 pr2} {lt a3 pr4} {ht a2
pr2}]
set i 0
foreach a ${alist} {
lappend args a${i} ${a}
incr i
}
set res ""
foreach {a b} ${args} {
append res " \$${a}"
}
foreach {*}${args} {
lappend result [eval list $res]
}
puts $result

And you will get the following.
{ht ht lt lt ht} {a3 a2 a1 a3 a2} {pr2 pr1 pr2 pr4 pr2}

Regards,
tomk