If you are not using Tcl 8.5, you can use arrays. Note that arrays are one-dimensional, but the key is an arbitrary string that can be used to fake multidimensionality:
array set foo {} foreach first {abc} { foreach second {abc} { foreach third {1 2 3} { lappend foo($first,$first$second) "$first$second$third" } } } parray data
and output it - note: array keys, unlike dictionary keys, are unordered:
foreach key [array names foo] { foreach elem $foo($key) { puts "$key\t$elem" } }
If you are given the keys (example "b" and "bc"), you can get the value this way:
set key1 b set key2 bc foreach elem $foo($key1,$key2) {puts $elem}
source share