[Tutor] Help with dictionary
Sean 'Shaleh' Perry
shalehperry@attbi.com
Sun, 07 Apr 2002 16:50:00 -0800 (PDT)
On 07-Apr-2002 Gordon W. Ayers wrote:
> PythonWin 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on
> win32.
> Portions Copyright 1994-2001 Mark Hammond (mhammond@skippinet.com.au) -
> see 'Help/About PythonWin' for further copyright information.
>>>> a =
> {"server":"mpilgrim","database":"master","uid":"sa","pwd":"secret"}
>>>> a
> {'pwd': 'secret', 'database': 'master', 'uid': 'sa', 'server':
> 'mpilgrim'}
>>>>
>
> In the above session, why is the dictionary contents reversed when I
> redisplay
> the dictionary?
dictionaries are fast because they store their contents in a special data
structure. You can make *NO* guarantees about what the data looks like in a
dictionary. If you change the dictionary everything may be in a completely
different order.
If you must keep the data in a certain order you should use a list.