Check out the solution suggested by Andreas Dieckmann:

“I ended up using one of Python’s abilities to handle lists which is called groupby() because I did not want my head to hurt thinking about how to go about this in Dynamo… 😉
Here’s how:
  1. Sort list by X values using the method Steve explains above
  2. Sort list by Z values 
    (Notice that within each group of equal Z values, the X values retain their order from the previous sort operation)
  3. Create a list of lists with XYZ values (sublist 0) and just Z values (sublist 1)
  4. Group that list of lists by the Z values (using a custom node with some Python code inside)
  5. Extract only the list of lists of XYZs by combining two map nodes
You will need the package Group List of Lists By Key for this to work.
(For what it’s worth, I also uploaded another package called Sort List Of Lists this week which was related to that project but isn’t needed here. But it might be worth checking out, too.)”

Heads-up:
https://twitter.com/Jbenoit44/status/420673580838293504