Sorting List by Dictionary-Provided Weights

  • Share this:

Code introduction


This function sorts the list `arg1` based on the weights provided in the dictionary `arg2`, where the keys of the dictionary are the elements of the list and the values are the corresponding weights.


Technology Stack : Sorting, dictionary comprehension, lambda expression

Code Type : Function

Code Difficulty : Intermediate


                
                    
def aordiff(arg1, arg2):
    return sorted(arg1, key=lambda x: arg2[x])