Custom Sort by Remainder and Value

  • Share this:

Code introduction


Sorts the input list first by the remainder of the elements divided by 10, and then by the elements themselves if the remainders are the same.


Technology Stack : List comprehension, lambda expression, sorting

Code Type : Function

Code Difficulty : Intermediate


                
                    
def acesort(array):
    return sorted(array, key=lambda x: (x % 10, x))