Â
In this we are going to see a basic program to sort a dictionary by key in Python Programming Language.
dict1 = {3: 'a',5: 'b',2: 'c',4: 'd',1: 'e'}
print("Dictionary before sorting: ",dict1)
print("-----------------------------------------------------")
for i in sorted(dict1):
print(i," --> ",dict1[i])
# Coded By DHIRAJ SHELKE
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP