(phixonline)--> with javascript_semantics sequence test = {{"UK","London"}, {"US","New York"}, {"US","Birmingham"}, {"UK","Birmingham"}} --------------------- -- probably stable -- --------------------- function cmp(object a, object b) return compare(a[2],b[2]) end function pp(custom_sort(cmp,deep_copy(test)),{pp_Nest,1}) ----------------------- -- guaranteed stable -- ----------------------- function tag_cmp(integer i, integer j) integer c = compare(test[i][2],test[j][2]) if c=0 then c = compare(i,j) end if -- (see note) return c end function sequence tags = custom_sort(tag_cmp,shuffle(tagset(4))) pp(extract(test,tags),{pp_Nest,1})