Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9259595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:41:40+00:00 2026-06-18T12:41:40+00:00

I have a dictionary like >>> x = {‘a’:2, ‘c’: 1, ‘b’:3} There is

  • 0

I have a dictionary like

>>> x = {'a':2, 'c': 1, 'b':3}

There is no method available in dictionary to sort the dictionary by value. I sorted it using

>>> sorted_x = sorted(x.iteritems(), key=operator.itemgetter(1))
>>> sorted_x
[('c', 1), ('a', 2), ('b', 3)]

but now when I convert to sorted_x to dictionary again by using loop. like

>>> new_dict = {}
>>> for i in sorted_x:
    new_dict[i[0]] = i[1]
>>> new_dict
{'a': 2, 'c': 1, 'b': 3}

The new_dict again remains unsorted. Why the python dictionary cannot be sorted by key? can anyone shed light on it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:41:41+00:00Added an answer on June 18, 2026 at 12:41 pm

    Dictionaries in python are hash maps. The keys are hashed in order to keep a fast access to the elements.

    This means that internally the elements must be ordered depending on the hash they generate, not depending on the order you want to give.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does VBA have dictionary structure? Like key<>value array?
I have a dictionary with key-value pairs like {a : (b,c,d,e)} . If i
I have a dictionary like the following. Key value pairs or username:name d =
I have a generic dictionary like so: data holds a dictionary (key, value) pair:
I have passed to template dictionary parameters like parameters={ 'value':'some_value', 'style':{} } and inside
I have a python dictionary like this {'OR': [{'AND': [{'column': 'XXX', 'operator': '=', 'value':
Say I have a dictionary like so: my_dict = {2:3, 5:6, 8:9} Is there
I have a dictionary like this : <dict> <key>ThemeName</key> <string>Theme1</string> <key>AddToFavoritesButton</key> <dict> <key>DownImage</key> <string>heart_selected.png</string>
I have a dictionary that goes like this: typedef struct dictNode { int key;
I have a huge dictionary something like this: d[id1][id2] = value example: books[auth1][humor] =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.