I have a list with sublist,
mylist = [['loan', 'finance'], ['dealer', 'dealers', 'dealership'], ['Data entry', 'data entry', 'enter data']]
I want to sort by using the length of the sublist, so that the output is expected as
reqlist = [['dealer', 'dealers', 'dealership'], ['Data entry', 'data entry', 'enter data'], ['loan', 'finance']]
I was trying to use sorting function
def take(element):
return len(element)
reqlist = sorted(reqlist, key = take)
I tried list.sort
mylist.sort(key=len)
it doesnt work and output 'reqlist' is not as expected and is same as 'mylist'. Any help required.