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,530 points
62 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

+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,760 points
194 views
0 votes
1 answer

Find the largest value in a dictionary

import operator stats = {'a':1000, 'b':3000, 'c': 100} max(stats.iteritems(), ...READ MORE

answered Jul 20, 2018 in Python by Nietzsche's daemon
• 4,260 points
174 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
58 views
0 votes
0 answers

How can we pass a variable value in python GOTO statement?

Alias is a runtime argument the value ...READ MORE

Feb 5 in Python by neppoliean
• 120 points
108 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 19, 2018 in Python by Shuvodip
113 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
• 57,530 points
51 views
0 votes
0 answers

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

And a few operations as well. READ MORE

May 10, 2019 in Python by Waseem
• 4,530 points
29 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
51 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 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 957 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 20, 2019 in Python by Mohammad
• 3,230 points
91 views