On 30Mar2016 22:53, Stephen Hansen <me+pyt...@ixokai.io> wrote:
On Wed, Mar 30, 2016, at 10:34 PM, tdspe...@gmail.com wrote:
as you can see the option element was added third but is the first one
displayed.
Is this just standard - I am using Python 3.5
The order of items in dictionaries is based on the hash value -- which
while stable, should be considered random and not reliable. If you want
to maintain insertion order, consider using an OrderedDict:
https://docs.python.org/3.5/library/collections.html#collections.OrderedDict
Alternatively, you can decide to not care, and to present the dictionary keys
in some arbitrary order of your chosing when printing output (commonest example
is probably lexically sorted).
On the other hand, if you really do want the insertion order then OrderedDict
is the way to do, as several others have mentioned.
Cheers,
Cameron Simpson <c...@zip.com.au>
--
https://mail.python.org/mailman/listinfo/python-list