Nested list of variable length to a tensor

Not sure if this helps but here is a solution I found on SO:

and here are solutions if the lengths are the same: