[Tutor] Curious dictionary printing

Mark Lawrence breamoreboy at yahoo.co.uk
Mon May 7 22:57:15 CEST 2012


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 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?
>

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.



More information about the Tutor mailing list