I am trying to make a function which takes an array and returns the array sorted by the depth:
sortArrDepth([1, [5, 6], [4, 67, [34]], 7])
Would return
[[1, 7], [5, 6, 4, 67], [34]]
However, it has to be able handle arrays with any max depth and I would prefer to not use any external modules. If it helps, here is a function to get the max depth:
def getAstDepth(ast):
depth = 0
for i in last:
if isinstance(i, list):
depth = max(getAstDepth(i), depth)
return depth
Any help appreciated!