David Crisp <[email protected]> writes:

> I am having a little problems with dicts returning data not alwyas in
> the same order depending on how long they are

That's right. The ‘dict’ type is a *non-ordered* collection.

The order you see when a dict is serialised (e.g. when you ask for it to
be rendered as a text string) is not predictable within your Python code.

> HOW do I read the dict in the order it was written?

Bluntly: You don't. If you are writing code that relies on the order of
insertion into the dict, then your code is wrong in its assumptions.

> If thats the wrong way of doing it,  what would be the correct way of
> doing it?

Either re-visit what you want to do in your code – you quite likely can
write it so that it's not dependent on the order of items – or you use a
different type.

So, what is it you're actually needing to do, and why is the order of
items relevant?

-- 
 \       “Give a man a fish, and you'll feed him for a day; give him a |
  `\    religion, and he'll starve to death while praying for a fish.” |
_o__)                                                       —Anonymous |
Ben Finney

_______________________________________________
melbourne-pug mailing list
[email protected]
https://mail.python.org/mailman/listinfo/melbourne-pug

Reply via email to