To sort by Z then X then Y as a function in a Python the input and return needed to be adjusted to work as a definition.
import clr
def sortbyZXY(orglst):
orglst.sort(key = lambda orglst: (orglst.Z, orglst.X, orglst.Y))
return orglst
input = IN[0]
result = []
for i in input:
result.append(sortbyZXY(i))
OUT = result