I have a dict which looks like this:
Unsorted:
12 {12 489} 29 {89 12} 27 {301 302} 26 {489 329} 8 {89 302} 55 {44 301}
I would like to sort it like this:
55 {44 301} 27 {301 302} 8 {89 302} 29 {89 12} 12 {12 489} 26 {489 329}
As you can see, most of the time the second key value of the preceding entry is identical to the first key entry of the following entry. ( 12
and 489
in the last two entries)
This although is no requirement. The 302
of the second and third entry also fullfills the requirement of a "chain" as it exists in both the second and the third entry.
The only thing I want to do is sorting these entries in such a way, that the values in braces form a uninterupted chain.
It does not matter if the result looks like in the example or if it is mirrored.
From TCL 8.6 on I could do something similar to Sort Tcl dict by value using stride. But I'm stuck with this (Tcl8.5.9) version. What is the easiest way to this?