好吧,你可以很容易地得到主键和次键的列表:
# You might choose different sorting rulesâ¦
set xs [lsort -unique [lmap xy [array names ar] {
lindex [split $xy ","] 0
}]]
set ys [lsort -unique [lmap xy [array names ar] {
lindex [split $xy ","] 1
}]]
然后您可以使用嵌套
foreach
info exists
要处理稀疏性:
foreach x $xs {
foreach y $ys {
if {[info exists ar($x,$y)]} {
...
...
}
}
}
8.6还没有?(开始节目吧!)你可以收集
xs
ys
这样地:
set xs {}
set ys {}
foreach xy [array names ar] {
lassign [split $xy ","] x y
lappend xs $x
lappend ys $y
}
set xs [lsort -unique $xs]
set ys [lsort -unique $ys]