Sorted List to Dictionary Conversion

  • Share this:

Code introduction


This function converts a sorted list into a dictionary, where the elements of the list become the dictionary's values, and their indices become the keys.


Technology Stack : Sorting (list), Enumeration (enum), Dictionary (dict)

Code Type : Function

Code Difficulty : Intermediate


                
                    
def sorted_list_to_dict(sorted_list):
    return dict(enumerate(sorted_list))