Reputation: 37
How to combine two list as a key value pair?
The number of elements in both the lists are same. I have two lists as follows.
set a "1 2 3"
set b "One two three"
How can I combine like the following dict['1':One,'2':two,'3':three]
Upvotes: 1
Views: 1658
Reputation: 4813
One feature of the foreach
command that is easily overlooked is that it can loop over multiple lists. So, your task can simply be done like this:
foreach k $a v $b {dict set d $k $v}
puts $d
Result: 1 One 2 two 3 three
Upvotes: 7