> Why is this happening, and how do I get it to work properly (returning
> element 0 - n, versus n - 0)?

Python dictionaries are unordered collections.  When we iterate across
them, we can not guarantee that we'll walk the elements in the order
that we inserted them.  The reason for that is because of the
underlying algorithm behind dictionaries, which is the hash table data
structure:

    http://en.wikipedia.org/wiki/Hash_table

where the keys are deliberately scattered evenly through the
underlying array, in what looks like "random" order, so that later
lookups can be very, very fast.


For your application, does it matter that you preserve some kind of
order of the key-value pairs?
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to