Sorting List Elements by Index in Another List

  • Share this:

Code introduction


Sorts the elements of the list arg1 based on their index positions in the list arg2.


Technology Stack : None, sorted, lambda

Code Type : Sort function

Code Difficulty : Intermediate


                
                    
def aordiff(arg1, arg2):
    if arg1 is None or arg2 is None:
        return None
    return sorted(arg1, key=lambda x: arg2.index(x))