Message info
 
To:tutor@python.org From:Mark Lawrence Subject:Re: [Tutor] Curious dictionary printing Date:Mon, 07 May 2012 21:57:15 +0100
 

On 07/05/2012 18:16, 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@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@gmail.com', 'stadium': 'Shea Stadium'}
>
> Why is it out of order?
>

Cos plain old dicts have no order, but this can be done with
http://docs.python.org/library/collections.html#ordereddict-objects

--
Cheers.

Mark Lawrence.

_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor