As I've contemplated the usage of dictionaries, I face the question of efficiency. Going back before most of you were probably born;<)) if I remember correctly dictionaries(assoc. arrays), having hashes, are efficient for storing sparse arrays with the added benefit of hiding the traversal of the dictionary looking for the proper key, and being much less efficient if looking for the value and trying to retrieve its key. But it also depends on the hash key and algorithm and how many spaces are "available" for filling. If a hash is created for a small array, which is known ahead of time with some possible hints, the array is efficient but has the distinct difficulty of use when more and more pairs are created, because either the new pair matches an already used hash point and a trail must be descended off of that particular hash point or a mechanism must be used to determine how the new pair should be stored elsewhere in the array like at the end and matching becomes time consuming. And/or, a new hash key and perhaps a different algorithm must be used for creating the larger array. Also, since the array allows for multiple keys pointing to possibly identical values, the array is not necessarily 1 to 1 (could be 1 to multiple although we use replacement of the value normally) and definitely cannot be onto: there is no rule that says the mapping from value back to key is singular and unique.
I've not had much use of dictionaries in the past so maybe I am missing something. As I contemplated dictionary use, it seems changing the order of entries is best left to double single arrays - which can be modified together when changing order. Dicts don't seem to support moving pairs around and in fact would be broken if changes were attempted. Kind of like using a real dictionary, you can have a word (key) have multiple meanings (values), and you can have multiple words (keys) having the same meaning (value). Again, with the difference from a real dictionary, our dicts can't have keys pointing to different values. But there are definitely uses for dicts. Seem right??? Clayton
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor