The best way I know of is to make your list into a list of lists: {{x1 y1} {x2 y2} ...} Then use "lsort" on index 0. Bob Rashkin
rrashkin@csc.com
I agree that if you have control over the format of the list, it's going to be a lot easier to sort them in the manner you want using Bong's tip. Unfortunately, sometimes you don't have the luxury of designing the data format.
Equally unfortunate, there's no obvious way of doing this kind of sorting in Tcl. The best way I've been able to figure out transforms the list into an array and back for speed and simplicity. Here's what I did:
The summary:
[ol][li]Use array set to create an array from the coordinate list.[/li]
[li]Use array names to retrieve a list of just the keys (the x coordinates, in this case).[/li]
[li]Sort the keys (x coordinates) using lsort -real.[/li]
[li]Loop through the sorted keys and use lappend to append the key and its corresponding value to the new, sorted list.[/li][/ol] - Ken Jones, President
Avia Training and Consulting
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.