How To Sort In Python With Multiple Conditions?
I have a list with sublists as follows: result = [ ['helo', 10], ['bye', 50], ['yeah', 5], ['candy',30] ] I want to sort this with three conditions: first, by highrest integer in
Solution 1:
every element is a list of 2 elements, sorting by the length of the list is useless because all of them has the same length, maybe you want to sort by the length of the first element so
finalresult = sorted(result, key=lambda word: (-word[1], len(word[0]), word[0]))
Post a Comment for "How To Sort In Python With Multiple Conditions?"