# Problem 28B

(Intermediate ðŸŒŸðŸŒŸ) Again, we suppose that a list contains elements that are lists themselves. But this time the objective is to sort the elements of this list according to their **length frequency**; i.e., in the default, where sorting is done ascendingly, lists with rare lengths are placed first, others with a more frequent length come later.

```
variable {Î± : Type}
/-- Insert an element in a way that
does not break the order of the sorted list. -/
def orderedInsert (a : Î±) (ord : Î± â†’ Nat) : List Î± â†’ List Î±
| [] => [a]
| b :: l =>
if ord a â‰¤ ord b then a :: b :: l
else b :: orderedInsert a ord l
/-- insertion sort -/
def insertionSort (ord : Î± â†’ Nat) : List Î± â†’ List Î±
| [] => []
| b :: l => orderedInsert b ord <| insertionSort ord l
-- You can use this!
#check insertionSort
def lfsort (l : List (List Î±)) : List (List Î±) :=
sorry
-- The following codes are for test and you should not edit these.
#guard lfsort ([[]] : List (List String)) = [[]]
#guard lfsort [[1, 2], [1], [1, 2]] = [[1], [1, 2], [1, 2]]
#guard lfsort [[1, 2], [1], [2, 3]] = [[1], [1, 2], [2, 3]]
```