From: hae on
On 29 Jul., 10:09, Uwe Klein <uwe_klein_habertw...(a)t-online.de> wrote:
> ashneerson wrote:
> > can someone please help with this?
>
> #!/usr/bin/tclsh
> proc prettyprintlist list {
>          puts \{
>          foreach line $list {
>                  puts -nonewline \t\{
>                  foreach item $line {
>                          puts -nonewline [ format %10s $item ]
>                  }
>                  puts \t\}
>          }
>          puts \}}
>

Hi,

here a version of prettyprintlist that works.

proc prettyprintlist list {
puts \{
foreach line $list {
puts -nonewline \t\{
foreach item $line {
puts -nonewline [ format %10s $item ]
}
puts \t\}
}
puts \}
}

From: hae on
On 29 Jul., 07:52, 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.

Hi,

this looks like you want to transpose a matrix. You could use
struct::matrix from tcllib. It already provides this functionality.

http://tcllib.sourceforge.net/doc/matrix.html

Rüdiger
From: hrachyag on
On Jul 29, 2:37 pm, hae <r_haer...(a)gmx.de> wrote:
> On 29 Jul., 07:52, 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.
>
> Hi,
>
> this looks like you want to transpose a matrix. You could use
> struct::matrix from tcllib. It already provides this functionality.
>
> http://tcllib.sourceforge.net/doc/matrix.html
>
> Rüdiger

thanks, Rüdiger! that helped. i wrote my own implementation for
transposing the list based on what they had there. thanks!
From: hrachyag on
On Jul 29, 1:09 pm, Uwe Klein <uwe_klein_habertw...(a)t-online.de>
wrote:
> ashneerson wrote:
> > can someone please help with this?
>
> #!/usr/bin/tclsh
> proc prettyprintlist list {
>          puts \{
>          foreach line $list {
>                  puts -nonewline \t\{\
>                  foreach item $line {
>                          puts -nonewline [ format %10s $item ]
>                  }
>                  puts \t\}\
>          }
>          puts \}}
>
> proc listrot list {
>          set columns {}
>          set col 0
>          foreach line $list {
>                  if {!$col} {
>                          foreach item $line {
>                                  lappend columns c:$col
>                                  incr col
>                          }
>                  }
>                  set col 0
>                  foreach item $line {
>                          lappend c(c:$col) $item
>                          incr col
>                  }
>          }
>          foreach tok $columns {
>                  lappend ret $c($tok)
>          }
>          return $ret}
>
> set ilist {
>          {0 1 2}
>          {0 1 3}
>          {0 2 1}
>          {1 1 2}
>          {1 2 3}}
>
> prettyprintlist $ilist
> set olist [ listrot $ilist ]
> prettyprintlist $olist
> #end

thanks Uwe for your help!
From: Uwe Klein on
hae wrote:
> here a version of prettyprintlist that works.
so where is your improvement ( except partly
fixing the issues some(your?) MUA inserted )?

uwe
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4
Prev: How to load large images in memory ?
Next: http question