Here's an example of smoothing, sorting, and then restoring nested lists, as suggested by @Inerdia in the comments above.
I tried to use generators and iterators where possible, but I'm sure there are smarter and more efficient ways to get 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)]
source share