Reputation: 1
I try to write a program which sort a list of lists by ascending number (number of elements in a list).
I think I have to use list.lenght
to retrieve the lenght of the lists, then I have to use list.sort
on these values. I struggle to find how to create a new list with list.lenght
. Not sure where to start.
Because it's not possible to use list.length
with a list of lists, for example list.length [[5;71;32] [33;32]];;
Upvotes: 0
Views: 512
Reputation: 66803
You can use List.length on any list:
# List.length [[5; 71; 32]; [33; 32]];;
- : int = 2
It's just that it doesn't really help with the sorting :-)
When you sort a list, you supply a comparison function. It can be any desired function that determines the desired order of the two value. You should be thinking about the comparison function that you want to use.
Upvotes: 1