... until the collector arrives ...

This "blog" is really just a scratchpad of mine. There is not much of general interest here. Most of the content is scribbled down "live" as I discover things I want to remember. I rarely go back to correct mistakes in older entries. You have been warned :)

2007-08-27

Splitting a Cross-product in Mathematica

In Mathematica, the following expression will split a relational cross-product back into its component parts (assuming that common keys are sorted together):

SplitCrossProduct[keys_, list_] :=
  {
    #[[1, keys]],
    #[[Complement[Range[1, Length[list]], keys]]] & /@ #
  }& /@ Split[list, SameQ[#1[[keys]], #2[[keys]]] &]

Blog Archive