[Tutor] Why is an OrderedDict not sliceable?

Ben Finney ben+python at benfinney.id.au
Thu Jan 21 12:12:08 EST 2016


Ben Finney <ben+python at benfinney.id.au> writes:

> Oscar Benjamin <oscar.j.benjamin at 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.

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



More information about the Tutor mailing list