Sorting the Elements of a Non Rectangular List

*To*: mathgroup at smc.vnet.net*Subject*: [mg51181] Sorting the Elements of a Non Rectangular List*From*: Richard Palmer <mapsinc at bellatlantic.net>*Date*: Thu, 7 Oct 2004 05:26:10 -0400 (EDT)*Sender*: owner-wri-mathgroup at wolfram.com

Make two data structures h1 and h2. \!\(\(h1 = Sort[Table[key\_\(Random[Integer, {1, 30}]\), {i, 1, 8}]] /. key\_i_ -> {key\_i, info\_\(i, 1\), info\_\(i, 2\)};\)\) \!\(\(h2 = Sort[Table[{key\_\(Random[Integer, {1, 30}]\), Sort[Table[ info\_\(Random[Integer, {3, 20}]\), {Random[ Integer, {0, 12}]}]]}, {9}]];\)\) Define a function tensorize which adds keys that aren't on one set onto another. tensorize[x_, using_] := Flatten[{x, Transpose[{Complement[First[Transpose[using]], First[Transpose[x]]]}]}, 1] How do I sort tensorize[h1,h2] into key order? Sort[tensorize[h1,h2]] does not work and Sort[tensorize[h1,h2],First[#1]<=Sort[#2]&] does not work? Thanks in advance.

**Follow-Ups**:**Re: Sorting the Elements of a Non Rectangular List***From:*Andrzej Kozlowski <akoz@mimuw.edu.pl>