Sorting Dictionary by Key Alphabetically

  • Share this:

Code introduction


This function takes a dictionary as input and returns a new dictionary with the keys sorted alphabetically.


Technology Stack : Sorting

Code Type : Sort function

Code Difficulty : Intermediate


                
                    
def sort_dict_by_key(d):
    return {k: d[k] for k in sorted(d)}                
              
Tags: