On Sun, Dec 27, 2015 at 11:36:30AM +1100, Chris Angelico wrote:
On Sun, Dec 27, 2015 at 11:34 AM, Wes Turner
wrote: * collections.abc.Ordered * collections.abc.Reversible * collections.abc.Infinite [...]
* collections.abc.Sorted ?
-1. Can you imagine trying to explain to everyone what the difference is between Ordered and Sorted? (My understanding is that Ordered has an inherent order, and Sorted will maintain an externally-defined order, but I might be wrong.)
The same problem comes up with OrderedDict. People often want a *sorted* dict, in the sense that it always iterates in the naive sorted order that sorted(dict.keys()) would give, but without having to sort the keys. So you will sometimes find people using "ordered" and "sorted" interchangably -- I must admit I've been guilty of that once or twice. In general, though, "ordered" means *items are always in insertion order*, while "sorted" means "the order you would get if you sorted". And neither may apply to data structures that order their items in something other than insertion order, e.g. order of frequency of use. -- Steve