Maybe note that UFL guarantees that coefficients come out sorted by their count, which is why you don't need to apply sorting here.