[Tutor] Curious dictionary printing

bob gailer bgailer at gmail.com
Tue May 8 04:31:54 CEST 2012

On 5/7/2012 1:16 PM, Cranky Frankie wrote:
> In 3.2.2 in IDLE I have this dictionary entry:
> Namath = {"first_name": "Joe", "last_name": "Namath", "phone": "212-222-7777",\
>            "email": "joe.namath at gmail.com", "stadium": "Shea Stadium"}
> when I print it:
> print(Namath)
> I get:
> {'phone': '212-222-7777', 'first_name': 'Joe', 'last_name': 'Namath',
> 'email': 'joe.namath at gmail.com', 'stadium': 'Shea Stadium'}
> Why is it out of order?

May I recommend a different approach to such questions.

When you get an unexpected (undesired)  result try saying - "Oh I see - 
that's how Python does it!"

I want something different. How can I get it?

Then try reading the documentation.

Asking why does it not do what I want is not IMHO the best way to win 
friends here.

Taking this steps further
  - what does it mean to be "in order". To some it is the order in which 
items are added rather than some collating sequence.
  - Do you want order by key or by value?
  - how would you order {1 : 'cat', "a": 3, (2,3): True}?

Bob Gailer
Chapel Hill NC

More information about the Tutor mailing list