Sorting Function Based on Custom Key

  • Share this:

Code introduction


This function sorts a list based on a given key. If the input is not a list, it converts it into one.


Technology Stack : Built-in function: sorted(), lambda expression

Code Type : Sort function

Code Difficulty : Beginner


                
                    
def aord(arg1, arg2):
    return sorted(arg1 if isinstance(arg1, list) else [arg1], key=lambda x: arg2(x))