[Tutor] Why is an OrderedDict not sliceable?
Steven D'Aprano
steve at pearwood.info
Wed Jan 20 20:00:29 EST 2016
On Wed, Jan 20, 2016 at 01:33:17PM +0000, Albert-Jan Roskam wrote:
> Hi,
>
> Like the subject says: Why is an OrderedDict not sliceable? (From the
> collections library). Was that an intentional omission, or a mistake?
> [1]
Because slicing a dict makes no sense. A dict is a mapping, not a
sequence.
d = OrderedDict()
d["cow"] = "a"
d["fox"] = "b"
d["ape"] = "c"
d["dog"] = "d"
d["bee"] = "e"
I can do a dict lookup on a key:
d["cow"]
What would a slice even mean? d[1:4] but 1, 2, 3 are not keys of the
dict.
--
Steve
More information about the Tutor
mailing list