> To: tutor@python.org > From: ben+pyt...@benfinney.id.au > Date: Fri, 22 Jan 2016 04:12:08 +1100 > Subject: Re: [Tutor] Why is an OrderedDict not sliceable? > > Ben Finney <ben+pyt...@benfinney.id.au> writes: > > > Oscar Benjamin <oscar.j.benja...@gmail.com> writes: > > > > > According to a narrow definition of indexed access. I would say that > > > d[k] is index access even if d is a dict and k a key. > > The sense of “index” implied is used consistently throughout Python > <URL:https://docs.python.org/3/glossary.html> to refer to the integer > ordinal position in a sequence.
I appear to have confused the terms "sorted" and "ordered" (see the email I just sent to Mark Lawrence). My OrderedDict was sorted on its keys, because I defined the dict using the result of an SQL query that ended with ORDER BY <names of dict keys here>. So in that case I needed a kind of "chameleon" datatype: both a mapping and an indexing type [1] [1] https://docs.python.org/2/reference/datamodel.html#object.__getitem__ > It is not compatible with key access into a mapping. > > > An index implies the ordinal position in a sequence. In a mapping, the > > key is *not* referring to the position in a sequence, so is not a key. > > “the key … is not an index”, I mean. > > > So accessing an item in a mapping by key is not indexed access. > > -- > \ “Facts do not cease to exist because they are ignored.” —Aldous | > `\ Huxley | > _o__) | > Ben Finney > > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor