sort associative array in tcl

65 Views Asked by At

I want to sort the array like this but can't find a way. Everyone help me!!!

I want to sort the array like this but can't find a way. L = {{55 746} {163 746} {163 778} {55 778}} {{939 746} {1047 746} {1047 778} {939 778}} {{277 746} {385 746} {385 778} {277 778}} {{721 746} {829 746} {829 778} {721 778}} {{1161 746} {1269 746} {1269 778} {1161 778}} {{1605 746} {1713 746} {1713 778} {1605 778}} {{499 746} {607 746} {607 778} {499 778}} {{1383 746} {1491 746} {1491 778} {1383 778}}

1

There are 1 best solutions below

1
Donal Fellows On

That actually looks like a list of lists of pairs. You normally sort those by passing a compound -index to lsort:

lsort -integer -index {0 0} $L

That won't overwrite the original variable; Tcl doesn't sort in place.