prelude: add ltranspose

main
magical 2023-12-19 04:54:36 +00:00
parent 7baf6aa596
commit ef2711b76f
1 changed files with 20 additions and 0 deletions

View File

@ -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}