Hi i have a list of parent-child items as follows :
set mylist {{1:0 2:0} {2:0 3:0} {3:0 4:0} {3:0 5:0} {3:0 6:0} {3:0 7:0}
{4:0 8:0} {5:0 9:0} {4:0 10:0} {5:0 11:0}};
Now i am trying to achieve couple of tasks here.
- Create a new list of unique items from the above list $mylist.
- Create an array with keys as the unique items from my newlist and values as some data that i have available.
So i created a new list using the below code.
set newlist [list];
foreach item $mylist {
lappend newlist [lindex $item 0];
lappend newlist [lindex $item 1];
}
which gave me output as
1:0 2:0 2:0 3:0 3:0 4:0 3:0 5:0 3:0 6:0 3:0 7:0 4:0 8:0 5:0 9:0 4:0 10:0 5:0 11:0
and then i did lsort -unique
set newlist [lsort -unique $newlist];
which gave me the unique list 1:0 10:0 11:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0
Now I create the array as below
array set newarr {
[lindex $newlist 0] {list of values}
[lindex $newlist 1] {list of values}
[lindex $newlist 2] {list of values}
[lindex $newlist 3] {list of values}
...
}
Which basically gives me what I wanted to achieve, but I was wondering if there is a better way to achieve the same task. For example, I was thinking if there is a better way of creating newlist from mylist, basically the unique newlist from mylist items??