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 8150507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:04:49+00:00 2026-06-06T15:04:49+00:00

Can I expect the keys() to remain in the same order? I plan to

  • 0

Can I expect the keys() to remain in the same order?

I plan to use them for a dropdown box and I dont want them to shift if I add or delete items from the dictionary.

  • 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-06T15:04:51+00:00Added an answer on June 6, 2026 at 3:04 pm

    The ordered of the keys in a dict is not guaranteed.

    The documentation says:

    It is best to think of a dictionary as an unordered set of key: value pairs, with the requirement that the keys are unique (within one dictionary)…

    The keys() method of a dictionary object returns a list of all the keys used in the dictionary, in arbitrary order (if you want it sorted, just apply the sorted() function to it).

    Python 2.7+ and 3.1+ have the OrderedDict class in collections as described by PEP 372, which does exactly what you want. It remembers the order in which keys were added:

    >>> from collections import OrderedDict
    >>> od = OrderedDict()
    >>> od[1] = "one"
    >>> od[2] = "two"
    >>> od[3] = "three"
    >>> od.keys()
    [1, 2, 3]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In order to use SetWindowsHookEx in a GUI application, you usually want in the
what behaviour can I expect when I run this code: do while(testA) { //
How much slower can I reasonably expect perform: to be than a literal message
I would expect subclass always call super() for some method. How can I enforce
echo date(W,strtotime('2010-01-01')); This outputs 53. I would expect it to output 1. Can anyone
Can 2 or more equations defining a function in Haskell share the same where
I have a class that inherits from a dictionary in order to add some
I can not figure out what the heck is happening here. What I expect
How can I catch a shift - some-key combination with this script? When I
Can a SharePoint expert explain to me the ;# in data returned by the

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.