Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

tcl combinations of lists

Status
Not open for further replies.

batarsehf

Programmer
Oct 20, 2011
1
US
Hello,
I am new to tcl programming and I am trying to write a tcl code to do list of every possible combinations of lists to build a table:

list 1 {a,b,c} 2 {d,e,f} 3 {g,h}

output:
a,d,g
a,d,h
a,e,g
a,e,h
a,f,g
a,f,h
b,d,g
b,d,h
...

Thanks for your help
 
Code:
set L0 {a b c}; set L1 {d e f}; set L2 {g h}; 

foreach n0 $L0 {foreach n1 $L1 {foreach n2 $L2 {puts "$n0 $n1 $n2 "}}}

this is just one way of doing it, a more dynamic method is possible but that requires more complexity.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top