[Tutor] key/value order in dictionaries
Tim Golden
mail at timgolden.me.uk
Thu Jul 31 10:33:20 CEST 2008
Steve Poe wrote:
> Hi tutor list,
>
> In dictionaries, I know that the keys are immutable, and the values
> can change What about the place/order of the key/order? I thought
> that they were sequential and they do not change.
You were wrong :)
A lot of electronic ink has been spilt on this subject
over the years, and if you Google for things like
"python ordered dictionary" you'll find various
discussions and implementations.
In CPython dictionaries won't generally change order
if nothing's inserted or changed. But you certainly don't
want to rely on that as a characteristic. A Python
dictionary is considered inherently unordered (rather
like a set).
TJG
More information about the Tutor
mailing list