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 in Python by Waseem
• 4,480 points
30 views

1 answer to this question.

0 votes

we can use OrderedDict

import collections

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

answered Mar 22 by Mohammad
• 3,170 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,720 points
89 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
77 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 in Python by moumita
• 120 points
41 views
0 votes
1 answer

Obtaining a value when given a key in python dicionaries

We cannot. Dictionaries aren't meant to be ...READ MORE

answered May 31, 2018 in Python by Nietzsche's daemon
• 4,260 points
42 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
92 views
0 votes
1 answer

What is a dictionary in Python?

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

answered Mar 4 in Python by Priyaj
• 57,300 points
35 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 in Python by Waseem
• 4,480 points
13 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 in Python by John
22 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 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 409 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 in Python by Mohammad
• 3,170 points
48 views