One liner function for sorting a string list of lists in ascending, descending order based on varying criteria in python
Let's assume that I have the following list of lists:
[[list1], [list2], ..., [listK]]
where list1, list2, ..., listK are lists of N strings.
[list1] = [string11, string12, ..., string1N] [list2] = [string21, string22, ..., string2N] . . . . . .
Now, let's say I want to choose some specific subset of inner list to be sorted in a descending order, and the rest in ascending order. For instance, let's assume that N=5, and I first would like to sort the outer list by sorting by first, third, fifth strings of the inner list in the ascending order and by then second and fourth strings in the descending order.
If I didn't care about the ascending/descending, and wanted to sort all in the ascending order, there would be an easy one liner solution to it:
outer_list.sort(key = lambda lst: (lst, lst, lst, lst, lst))
but since we have a condition: first, third, fifth strings of the inner list in the ascending order and then by second and fourth strings in the descending order, I was wondering if there's a simple addition to the code above to make it a one liner solution.