top of page

Python Program to Sort Python Dictionaries by Key or Value

  • Writer: Rajesh Singh
    Rajesh Singh
  • Feb 18, 2023
  • 1 min read

Program: This program is most for practical Exam. So read carefully and understand:



mydict = {'raj': 5, 'raja': 6,

'sanju': 7, 'mohan': 2, 'surya': 10}

Keys = list(mydict.keys())

Keys.sort()

sort_dict = {i: mydict[i] for i in Keys}

print(sort_dict)



Output:

{'mohan': 2, 'raj': 5, 'raja': 6, 'sanju': 7, 'surya': 10}



Recent Posts

See All

コメント


bottom of page