Question: How to Determine Nesting Levels in a List of Lists in Maple?

Hello,

I would like to determine the level of nested lists within a list.

For example, given:

L := [[1, 2, 3], [], [[1, 2], [3, 4], [5, 6]], [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]];

I would like to compute:

nL := [1, 1, 2, 3];

That is, for each element in L, return the depth of nesting.

Additionally, I would like to write a procedure that takes L and returns a flattened version at the first non-empty list level:

L1 := [[1, 2, 3], [], [1, 2], [3, 4], [5, 6], [1, 2], [3, 4], [5, 6], [7, 8]];

Thank you in advance for your help!

Ed

Please Wait...