[Tutor] Why is an OrderedDict not sliceable?

Steven D'Aprano steve at pearwood.info
Tue Jan 26 10:24:35 EST 2016


On Sun, Jan 24, 2016 at 07:47:47PM +0000, Albert-Jan Roskam wrote:

> > You appear to be confusing ordered and sorted.   
> 
> You are correct. Is there a difference in the way those terms are 
> used colloquially vs. in the field of Computer Science (Note: English 
> is not my mother tongue)? 

In ordinary English, "ordered" and "sorted" often are used to mean the 
same thing. People do often use sorted and ordered as interchangeable, 
but the definitions are slightly different:



ordered \ordered\ adj.
   1. having or evincing a systematic arrangement; especially,
      having elements succeeding in order according to rule; as,
      an ordered sequence; an ordered pair. Opposite of
      disordered or unordered. [Narrower terms:
      abecedarian, alphabetical; {consecutive, sequent,
      sequential, serial, successive ]
      [WordNet 1.5 +PJC]

   2. arranged in order.

Sort \Sort\, v. t. [imp. & p. p. Sorted; p. pr. & vb. n.
   Sorting.]
   1. To separate, and place in distinct classes or divisions,
      as things having different qualities; as, to sort cloths
      according to their colors; to sort wool or thread
      according to its fineness.
      [1913 Webster]


The way I would put it is that "sorted" means the items are ordered 
according to some specific rule or property of the items themselves, 
e.g. to sort your clothes by colour. "Ordered" is more general: it just 
means to have some order, which may be according to a rule or property, 
or it may be in whatever sequence the items happen to have.

Books on a shelf have some order, the order that they appear when you 
read them from left to right, regardless of whether they are sorted by 
author, title, height, colour or at random. Books jumbled up in a bag 
have no order.

Ordinary dicts are like books in a bag. You reach in and grab whatever 
book happens to come to hand first. OrderedDicts are like books on a 
shelf: you can systematically touch each book in order starting from the 
left, and new books are always added to the right.

-- 
Steve


More information about the Tutor mailing list