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

  • Home
  • SEARCH
  • 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 7967195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:37:48+00:00 2026-06-04T06:37:48+00:00

Possible Duplicate: In what order does python display dictionary keys? There was this very

  • 0

Possible Duplicate:
In what order does python display dictionary keys?

There was this very weird Python question which I was trying to answer (on SO but looks like the author deleted it). This has gotten me head-over-heels and I cannot seem to plausibly explain myself what could be the cause behind this flummoxing phenomenon.
I have a Python dictionary (associative array) which I initialize as below.

d = {"word1": 1, "word2": 2, "word3": 3}

And loop through it using a for..in construct in which i print the keys of “d” separated by a space.
Expected output: word1 word2 word3
Actual output: word1 word3 word2

I then tried to print “d” as

 print d 

Output

{'word1': 1, 'word3': 3, 'word2': 2}

I was scanning the online Python docs, existing questionnaire on SO, blogs but fully failed to figure out the cause. Am I missing something here? Furthermore, there’s a kind request to all those who down-vote this question to please elaborate on the reason for the same.

Cheers. 🙂

  • 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-04T06:37:50+00:00Added an answer on June 4, 2026 at 6:37 am

    From the documentation:

    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). A pair of braces creates an empty dictionary: {}. Placing a comma-separated list of key:value pairs within the braces adds initial key:value pairs to the dictionary; this is also the way dictionaries are written on output.

    The main operations on a dictionary are storing a value with some key and extracting the value given the key. It is also possible to delete a key:value pair with del. If you store using a key that is already in use, the old value associated with that key is forgotten. It is an error to extract a value using a non-existent key.

    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). To check whether a single key is in the dictionary, use the in keyword.

    http://docs.python.org/tutorial/datastructures.html

    The last paragraph says it all.

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

Sidebar

Related Questions

Possible Duplicate: Does readdir() guarantee an order? I'm guessing this isn't the case, and
Possible Duplicate: Does fast enumeration in Objective-C guarantee the order of iteration? Just a
Possible Duplicate: Python analog of natsort function (sort a list using a “natural order”
Possible Duplicate: splitting a string i have a string which looks like this: http://pastebin.com/m5508ff19
Possible Duplicate: C++ Header order My question is about includes in .h files. Is
Possible Duplicate: STL containers element destruction order Is there a guarantee the the elements
Possible Duplicate: Why does this trigger fail? It says invalid identifier. CREATE MATERIALIZED VIEW
Possible Duplicate: Reference - What does this symbol mean in PHP? I've been programming
Possible Duplicate: In what order does evaluation of post-increment operator happen? Consider the following
Possible Duplicate: Is short-circuiting boolean operators mandated in C/C++? And evaluation order? Is there

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.