I currently have a list of lists, something of this kind:
[['NJ', '10', '2000', '500', '20', '02-03-19', '15:20'],
['NJ', '15', '1500', '600', '20', '02-03-19', '15:30'],
['NYC', '25', '1500', '500', '10', '02-03-19', '15:30'],
['NYC', '15', '1200', '700', '1', '02-03-19', '15:35']]
And I need to sort them with several elements in mind, for example, let's say, in terms of index numbers, 0 is area, 1 is weight, 2 is distance, 3 is height, 4 is autonomy, 5 is date and 6 is a timestamp. I am already sorting all of the elements using this:
list.sort(key=itemgetter(0, time_sorter, 4, 3))
Where time_sorter() is a function I had previously built that sorts lists based on element time stamps. My problem is that I need to sort this list with "area" in mind. For example, say I need to sort the list with all those elements in mind, as I am, but I would also like to sort it, simultaneously, in way that the elements which have "NYC" on their 0 index position are placed first, how do I go about this?
Bonus question would be: If I have multiple parameters in itemgetter()
or the sort "key" parameter itself, and I want the sorting to be reverse but for only one of those arguments, how do I go about that?
Is my best option really to separate all these sorts into several functions and call those in the sort key?
Thanks in advance!