Considering I have an iterated "lists of lists ..." (up to 4 dimensions), now I wish to make the full list "rectangular" (or well each dimension equal in size). For a 4 dimensional case I've written out a specific version:
x=[[[[4,3,4,5],,[2,2]],[[3,6,7],[2,3],]],[[]]] length0 = len(x) length1 = len(sorted(x,key=len, reverse=True)) length2 = 0 length3 = 0 for xi in x: lengthi = len(sorted(xi,key=len, reverse=True)) for xii in xi: lengthii = len(sorted(xii,key=len, reverse=True)) length3 = max(lengthii, length3) length2 = max(lengthi, length2) tlist3 = [None] tlist2 = [tlist3 * length3] tlist1 = [tlist2 * length2] for xi in x: for xii in xi: for xiii in xii: xiii.extend(tlist3*(length3 - len(xiii) )) xii.extend(tlist2*(length2 - len(xii))) xi.extend(tlist1 * (length1 - len(xi))) print(x)
It works, but that's everything I can say about this code (it doesn't look clean, nor is it scalable to more dimensions easily).
Ideally I would've a function that goes up to N dimensions into a given list, and rectangulars everything
As a side note: this is for insertion into a NumPy array.