prelude: add ltranspose
parent
7baf6aa596
commit
ef2711b76f
20
prelude.tcl
20
prelude.tcl
|
@ -57,6 +57,26 @@ proc transpose strings {
|
|||
return $out
|
||||
}
|
||||
|
||||
# transpose a list of lists
|
||||
#
|
||||
# % ltranspose {{a b c} {1 2 3}}
|
||||
# {a 1} {b 2} {c 3}
|
||||
# % ltranspose {{a 1} {b 2} {c 3}}
|
||||
# {a b c} {1 2 3}
|
||||
#
|
||||
proc ltranspose lists {
|
||||
set out {}
|
||||
set C [llen [lindex $lists 0]]
|
||||
for {set i 0} {$i < $C} {incr i} {
|
||||
set column {}
|
||||
foreach row $lists {
|
||||
lappend column [lindex $row $i]
|
||||
}
|
||||
lappend out $column
|
||||
}
|
||||
return $out
|
||||
}
|
||||
|
||||
# extracts one or more indexes from a strided list
|
||||
# e.g.
|
||||
# % set l {0 1 2 a b c x y z}
|
||||
|
|
Loading…
Reference in New Issue