What would be the most efficient/clean way to deeply sort a multidimensional list in Python?
Question: Example:  
From this list:  

    
    
    list = [[10, 9, 1], [2, 1, 1,], [4, 11, 16]]
    

I'd like to have:

    
    
    print list
    [[1, 1, 1], [2, 4, 9], [10, 11, 16]]
    

Is it possible with the _list.sort()_ function or do I have to write a custom
loop ?


Answer: Here's an example of flattening, sorting, then rebuilding the nested lists, as
@Inerdia suggested in the comments above.

I've tried to use generators and iterators where possible, but I'm sure there
are cleverer, more efficient ways of getting the result!

    
    
    from itertools import izip
    
    l = [[10, 9, 1], [2, 1, 1,], [4, 11, 16]]
    # flatten the list and sort it
    f = sorted(inner for outer in l for inner in outer)
    # group it into 3s again using izip
    new_list = [list(l) for l in izip(*[iter(f)]*3)]
    

