You can download this code by clicking the button below.
This code is now available for download.
This function sorts the elements of a list based on the weights defined in a dictionary
Technology Stack : list comprehension, lambda expression, sorted function, exception handling
Code Type : Sort function
Code Difficulty : Intermediate
def aordn(arg1, arg2):
try:
return sorted(arg1, key=lambda x: arg2[x])
except TypeError:
return "Error: Arguments must be a list and a dictionary with corresponding keys"