can we sort the key value pairs in a dictionary

0 votes
since the dictionary is unordered, is there a way to sort the dictionary?
Mar 22, 2019 in Python by Waseem
• 4,540 points
582 views

1 answer to this question.

0 votes

we can use OrderedDict

import collections

result = colections.OrderedDict(sorted(dictionaryname.items()))

answered Mar 22, 2019 by Mohammad
• 3,230 points

Related Questions In Python

0 votes
3 answers

How can I sort a dictionary by key in python?

Another way could be: color_dict = {'red':'#FF0000',           'green':'#008000',           'black':'#000000',           'white':'#FFFFFF'} for ...READ MORE

answered Dec 28, 2020 in Python by Thomas Walenta
1,126 views
+2 votes
2 answers

In a list of dictionaries, how can I find the minimum calue in a common dictionary field.

There are several options. Here is a ...READ MORE

answered Apr 10, 2018 in Python by charlie_brown
• 7,720 points
1,432 views
0 votes
2 answers

Find the largest value in a dictionary

Use below running code which is simple ...READ MORE

answered Nov 25, 2021 in Python by Suhas
1,243 views
0 votes
0 answers

How can we save the extracted file in a specified folder?

While extracting the data using python selenium, ...READ MORE

Nov 7, 2019 in Python by moumita
• 120 points
487 views
0 votes
1 answer

I have a dictonary in python how to access the value field?

dic={"car":["limo","sedan"]} print (dic.keys())    <-----------------------Fetch the key "car" print (dic['car'][0])   <------------------------Fetch ...READ MORE

answered Dec 20, 2018 in Python by Shuvodip
828 views
0 votes
1 answer

What is a dictionary in Python?

Dictionary can be understood as a key-value ...READ MORE

answered Mar 4, 2019 in Python by Priyaj
• 58,020 points
704 views
0 votes
1 answer

can you give an example to get a random sample dictionary?

Check below code thisdict = { "1": ...READ MORE

answered Nov 25, 2021 in Python by anonymous
564 views
0 votes
1 answer

How to find count/length of dictionary values of list?

You should have used d.itervalues() instead and ...READ MORE

answered May 13, 2019 in Python by John
2,429 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,464 views
0 votes
1 answer

How can I find the square of a number in python?

You can use the exponentiation operator or ...READ MORE

answered May 21, 2019 in Python by Mohammad
• 3,230 points
1,261 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP