Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am fairly new to Python. Infact, today is my first day in Python. I was following a tutorial and read about dictionary.

But I don't know what is the order in which contents of a dictionary are displayed.

Below is my code:

dir = {'Z':1,'Y':3,'X':5,'V':7,'U':9,'T':2,'S':4,'R':6,'Q':8,'P':10};
print dir;

and following is the Output:

{'Q': 8, 'P': 10, 'S': 4, 'R': 6, 'U': 9, 'T': 2, 'V': 7, 'Y': 3, 'X': 5, 'Z': 1}

Can anybody explain how I get this output and not the list in its original sequence.

P.S: Sorry for a lame question :(
Posted

1 solution

Dictionaries are unordered sets, so the contents may appear in any sequence. See section 5.5 on this page[^].
 
Share this answer
 
Comments
ayesha hassan 16-May-13 7:58am    
Thank you so much :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900