I have a list that is a key value paired list. Something like the following
key1 value1 key2 value2 key3 value3
I would like to map this to an array or a dictionary.
Currently, my code looks like this
for {set i 0} {$i < [llength $list]} {incr i} {
if {[expr {fmod($i,2)}] == 0} {
set key [lindex $list $i]
} else {
set v_array(${key}) [lindex $list $i]
}
}
In perl, I know this can be assigned into a key value dictionary in one pass. Is there such simpler method in Tcl?