Sorting List #a# by Index in List #b#

  • Share this:

Code introduction


The function sorts the list a based on the index of elements in list b.


Technology Stack : Built-in functions: sorted, lambda expression

Code Type : Sort function

Code Difficulty : Intermediate


                
                    
def aaaa(a, b):
    return sorted(a, key=lambda x: b.index(x))